看起来像 Test::Deep 受到启发 is_deeply. 。我的问题是我该如何制作 cmp_deeply 测试的一部分而不是测试本身?因为我的测试列表只列出了 8 个,但每次我使用 cmp_deeply, ,它算作一次测试,使我的实际测试次数为 11(因为我称 cmp_deeply 3次)​​当我只有8个功能时。我不想增加测试数量。有没有更可行的解决方案?

有帮助吗?

解决方案

您应该使用eq_deeply代替:

  

这是一样的cmp_deeply()   除了它刚刚返回true或false。   它不会创建诊断...

其他提示

您可以做很多事情,但是如果不了解测试中的更多细节,就很难知道哪一个是最合适的:

  • 不要计划特定数量的测试。

    use Test::More;
    
    all(
        cmp_deeply($got0, $expected0),
        cmp_deeply($got1, $expected1),
        cmp_deeply($got2, $expected2)
       );
    
    # ... your other 7 tests
    done_testing();  # signals that we're all done.. exiting normally.
    
  • 动态确定正在运行的测试数量,如果您正在测试一些深层且动态的结构,其复杂性(以及所需的测试数量)事先未知,则这是有意义的:

    use Test::More;
    use Test::Deep;
    
    # perhaps this is in some sort of loop?
    cmp_deeply($got0, $expected0);  $numTests++;
    cmp_deeply($got1, $expected1);  $numTests++;
    cmp_deeply($got2, $expected2);  $numTests++;
    
    # ... your other 7 tests
    
    # TAP output must be either at the beginning or end of all output
    plan tests => $numTests + 7;
    
    # no more tests here!
    exit;
    
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top