1

I'm exploring DUnitX for the first time and rebuilding a Windows 10 calculator clone to practice test-driven development. I have three test classes (paralleling a main CalculatorLogic class, an Equation class, and an Operand class). I've written four tests for Operand that simply assert that a value (float) or operator (enum) set in the Operand object is the same received from the 'get' method. Set/Get validation.

unit OperandTest;

interface

uses
  DUnitX.TestFramework, Vcl.Dialogs, Operands, Operation, System.Rtti;

type
  [TestFixture]
  OperandTester = class

  private
    op : Operand;

  public
    [Setup]
    procedure Setup;
    [TearDown]
    procedure TearDown;


    [Test]
    [TestCase('0','0')]
    [TestCase('0.0','0.0')]
    [TestCase('-0.1','-0.1')]
    [TestCase('maxInt','MaxInt')]
    [TestCase('maxLongInt','MaxLongInt')]
    [TestCase('0.00000000001','0.00000000001')]
    procedure TestGetValueSet(const setValue : Real);

    [Test]
    [TestCase('0/1','0,1')]
    [TestCase('-0.1/0.1','-0.1,0.1')]
    [TestCase('99999999999/0','99999999999,0')]
    [TestCase('0.00000000001/0.1','0.00000000001,0.1')]
    procedure TestNotGetValueNotSet(const setValue, falseValue : Real);


    [Test]
    [TestCase('Add','OpType.Add')]
    [TestCase('Nothing','OpType.Nothing')]
    procedure TestGetOpSet(const setOp : OpType);

    [Test]
    [TestCase('Add/Nothing','OpType.Add,OpType.Nothing')]
    [TestCase('Nothing/Multiply','OpType.Nothing,OpType.Multiply')]
    [TestCase('Nothing/Nothing','OpType.Nothing,OpType.Nothing')]
    procedure TestNotGetOpNotSet(const setOp, falseOp : OpType);

  end;

The issue I'm facing is that the 10 tests for value (first two functions) run but the second two for operator do not. The following DUnitX report shows 14 tests, 10 for the OperandTest value tests and 4 dummy tests for the other test units. No indication of TestGetOpSet or TestNotGetOpNotSet in the report, no indication that they were ignored, and a ShowMessage in those procedures is not executed.

**********************************************************************
*        DUnitX - (c) 2015-2018 Vincent Parrett & Contributors       *
*                                                                    *
*        License - http://www.apache.org/licenses/LICENSE-2.0        *
**********************************************************************

  Fixture : EquationTest
  -------------------------------------------------
     Fixture : EquationTest.EquationTester
     -------------------------------------------------
       Test : EquationTest.EquationTester.Test1
       -------------------------------------------------
       Running Setup for : Test1

       Executing Test : Test1


        Running Teardown for Test : Test1

         Success.

       Test : EquationTest.EquationTester.Test2
       -------------------------------------------------
       Running Setup for : Test2

       Executing Test : Test2


        Running Teardown for Test : Test2

         Success.

      Running Fixture Teardown Method : Destroy



  Fixture : CalcTest
  -------------------------------------------------
     Fixture : CalcTest.VCLCalcTester
     -------------------------------------------------
       Test : CalcTest.VCLCalcTester.Test1
       -------------------------------------------------
       Running Setup for : Test1

       Executing Test : Test1


        Running Teardown for Test : Test1

         Success.

       Test : CalcTest.VCLCalcTester.Test2
       -------------------------------------------------
       Running Setup for : Test2

       Executing Test : Test2


        Running Teardown for Test : Test2

         Success.

      Running Fixture Teardown Method : Destroy



  Fixture : OperandTest
  -------------------------------------------------
     Fixture : OperandTest.OperandTester
     -------------------------------------------------
       Test : OperandTest.OperandTester.TestGetValueSet.0
       -------------------------------------------------
       Running Setup for : TestGetValueSet.0

       Executing Test : TestGetValueSet.0


        Running Teardown for Test : TestGetValueSet.0

         Success.

       Test : OperandTest.OperandTester.TestGetValueSet.0.0
       -------------------------------------------------
       Running Setup for : TestGetValueSet.0.0

       Executing Test : TestGetValueSet.0.0


        Running Teardown for Test : TestGetValueSet.0.0

         Success.

       Test : OperandTest.OperandTester.TestGetValueSet.-0.1
       -------------------------------------------------
       Running Setup for : TestGetValueSet.-0.1

       Executing Test : TestGetValueSet.-0.1


        Running Teardown for Test : TestGetValueSet.-0.1

         Success.

       Test : OperandTest.OperandTester.TestGetValueSet.maxInt
       -------------------------------------------------
       Running Setup for : TestGetValueSet.maxInt

       Executing Test : TestGetValueSet.maxInt


        Running Teardown for Test : TestGetValueSet.maxInt

         Success.

       Test : OperandTest.OperandTester.TestGetValueSet.maxLongInt
       -------------------------------------------------
       Running Setup for : TestGetValueSet.maxLongInt

       Executing Test : TestGetValueSet.maxLongInt


        Running Teardown for Test : TestGetValueSet.maxLongInt

         Success.

       Test : OperandTest.OperandTester.TestGetValueSet.0.00000000001
       -------------------------------------------------
       Running Setup for : TestGetValueSet.0.00000000001

       Executing Test : TestGetValueSet.0.00000000001


        Running Teardown for Test : TestGetValueSet.0.00000000001

         Success.

       Test : OperandTest.OperandTester.TestNotGetValueNotSet.0/1
       -------------------------------------------------
       Running Setup for : TestNotGetValueNotSet.0/1

       Executing Test : TestNotGetValueNotSet.0/1


        Running Teardown for Test : TestNotGetValueNotSet.0/1

         Success.

       Test : OperandTest.OperandTester.TestNotGetValueNotSet.-0.1/0.1
       -------------------------------------------------
       Running Setup for : TestNotGetValueNotSet.-0.1/0.1

       Executing Test : TestNotGetValueNotSet.-0.1/0.1


        Running Teardown for Test : TestNotGetValueNotSet.-0.1/0.1

         Success.

       Test : OperandTest.OperandTester.TestNotGetValueNotSet.99999999999/0
       -------------------------------------------------
       Running Setup for : TestNotGetValueNotSet.99999999999/0

       Executing Test : TestNotGetValueNotSet.99999999999/0


        Running Teardown for Test : TestNotGetValueNotSet.99999999999/0

         Success.

       Test : OperandTest.OperandTester.TestNotGetValueNotSet.0.00000000001/0.1
       -------------------------------------------------
       Running Setup for : TestNotGetValueNotSet.0.00000000001/0.1

       Executing Test : TestNotGetValueNotSet.0.00000000001/0.1


        Running Teardown for Test : TestNotGetValueNotSet.0.00000000001/0.1

         Success.

      Running Fixture Teardown Method : Destroy



Done testing.
Tests Found   : 14
Tests Ignored : 0
Tests Passed  : 14
Tests Leaked  : 0
Tests Failed  : 0
Tests Errored : 0
Done.. press <Enter> key to quit.

I'm having a hard time finding sample code or tutorials with more than two test procedures so I don't know if there's any additional notation I need to add to successive tests. What am I missing? What formatting or DUnitX notation is incorrect/missing that would make the test suite completely ignore the last two tests? Thanks!

Procedure implementation, if it helps:

procedure OperandTester.TestGetValueSet(const setValue : Real);
begin
        op.setValue(setValue);
        Assert.AreEqual(op.getValue(), setValue);
end;

procedure OperandTester.TestNotGetValueNotSet(const setValue, falseValue : Real);
begin
        op.setValue(setValue);
        Assert.AreNotEqual(op.getValue(), falseValue);
end;


procedure OperandTester.TestGetOpSet(const setOp : OpType);
begin
        ShowMessage ('TestGetOpSet');
        op.setOperation(setOp);
        Assert.AreEqual(op.getOperation(), setOp);
end;

procedure OperandTester.TestNotGetOpNotSet(const setOp, falseOp : OpType);
begin
   
        op.setOperation(setOp);
        Assert.IsFalse(Ord(op.getOperation())= Ord(falseOp));
end;
ildrummer
  • 21
  • 4
  • 1
    Tom, I've tried reordering all the tests and also commenting out the tests that run, leaving only the Operator tests. The mystifying thing is that DUnitX skips the Operator tests completely even though they compile fine and are the only tests in the file. – ildrummer Nov 18 '20 at 22:49
  • How is `OpType` defined? The issue is probably related to that type. – Olivier Nov 19 '20 at 11:26
  • Did you include the unit in the uses clause where OpType is defined to your testsuite unit? – whosrdaddy Nov 19 '20 at 12:36
  • 2
    You need to edit your post and include a [mre] – Tom Brunberg Nov 19 '20 at 13:22
  • I vaguely recalled that Sets do NOT parse in DUnitX tests, just tried on Rio and although the test was run the set was empty no matter which format was used. – FredS Nov 19 '20 at 19:58
  • My issue turned out to be setting integer values on each of my Operation Enum values (previous troubleshooting attempt to figure out which Assert to use). Once I deleted those, DUnitX found the tests. Thanks for the lesson on minimal reproducible examples - my apologies for not providing everything needed. – ildrummer Nov 20 '20 at 23:18
  • It is indeed necessary to know how `OpType` is defined. But also then: my experience so far is that tests will run, even if the parameter input is not recognized correctly. In case `OpType` is an enumeration, you only should put in the enumeration name without the type/scope. Even if they have {$SCOPEDENUMS ON} defined. – Kees de Kraker Dec 17 '22 at 10:52

0 Answers0