1

我第一次探索 DUnitX 并重建 Windows 10 计算器克隆以练习测试驱动开发。我有三个测试类(并行主 CalculatorLogic 类、一个 Equation 类和一个 Operand 类)。我已经为 Operand 编写了四个测试,它们只是断言在 Operand 对象中设置的值(浮点数)或运算符(枚举)与从“get”方法接收到的相同。设置/获取验证。

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;

我面临的问题是 10 个值测试(前两个函数)运行,但后两个运算符没有运行。以下 DUnitX 报告显示了 14 个测试,其中 10 个用于 OperandTest 值测试,4 个用于其他测试单元的虚拟测试。报告中没有任何迹象,TestGetOpSetTestNotGetOpNotSet没有迹象表明它们被忽略,并且这些过程中的 ShowMessage 没有被执行。

**********************************************************************
*        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.

我很难找到包含两个以上测试过程的示例代码教程,所以我不知道是否需要在后续测试中添加任何其他符号。我错过了什么?什么格式或 DUnitX 符号不正确/缺失会使测试套件完全忽略最后两个测试?谢谢!

程序实施,如果有帮助:

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;
4

0 回答 0