Skip to content

Instantly share code, notes, and snippets.

@ritalin
Created April 17, 2014 04:35
Show Gist options
  • Save ritalin/10953068 to your computer and use it in GitHub Desktop.
Save ritalin/10953068 to your computer and use it in GitHub Desktop.
Should-base unit test for DUnitX
unit ExampleTest;
interface
uses
DUnitX.TestFramework;
type
[TestFixture]
TMyTestObject = class(TObject)
public
[SetUp]
procedure Setup;
[TearDown]
procedure TeaDown;
[Test]
procedure Test1;
[Test]
[TestCase('TestA', '1, 2')]
[TestCase('TestB', '3, 4')]
procedure Test2(const AVal1: integer; AVal2: integer);
end;
implementation
uses
Should, Should.Constraint.CoreMatchers, TestExceptionHandler.DUnitX
;
{ TMyTestObject }
procedure TMyTestObject.Setup;
begin
end;
procedure TMyTestObject.TeaDown;
begin
end;
procedure TMyTestObject.Test1;
begin
Its('Age').Val(17).Should(EqualTo(17));
Its('Age').Val(17).Should(not EqualTo(38));
Its('Age').Val(17).Should(EqualTo(38) or EqualTo(17));
Its('pi').Val(3.14).Should(GraterThan(3) and LessThanOrEqualTo(3.2));
Its('Name').Val('Hoge').Should(EqualTo('Hoge'));
Its('Name').Val('Hoge').Should(not EqualTo('Uge'));
Its('nil Object').Val(nil).Should(BeNil);
Its('Object').Val(TObject.Create).Should(not BeNil);
Its('Class').Val(TObject).Should(not BeNil);
Its('True').Val(true).Should(BeTrue);
Its('False').Val(false).Should(not BeTrue);
end;
procedure TMyTestObject.Test2(const AVal1: integer; AVal2: integer);
begin
end;
initialization
TDUnitX.RegisterTestFixture(TMyTestObject);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment