【问题标题】:Codeception/PHPUnit Assert::isTrue pass with falseCodeception/PHPUnit Assert::isTrue 通过 false
【发布时间】:2018-02-22 12:30:56
【问题描述】:

为什么下面的测试通过了,这有意义吗?

<?php
use \Codeception\Util\Debug;
use \PHPUnit\Framework\Assert;

class TrackingCest
{
    // tests
    public function tryToTest(AcceptanceTester $I)
    {
        Debug::debug("I am really here!");
        Assert::isTrue(false);
    }
}

【问题讨论】:

    标签: codeception


    【解决方案1】:

    enricog 是对的,你需要使用

    $I->assertTrue(false);
    

    但是你需要在你的配置中启用 Asserts 模块,在acceptance.suite.yml:

    classname: AcceptanceTester
    modules: 
        enabled:
            - Asserts
    

    除此之外,无需使用顶部的 use 语句。 您的测试可能如下所示:

    <?php
    
    class TrackingCest
    {
        // tests
        public function tryToTest(AcceptanceTester $I)
        {
            codecept_debug("I am really here!");
            $I->assertTrue(false);
        }
    }
    

    【讨论】:

      【解决方案2】:

      你实际上没有检查任何东西。

      查看 PHPUnits Assert::isTrue 方法的实现,它只返回一个新的 IsTrue 实例:

      PHPUnit::Assert

      要使用 codeception 检查是否为真,您应该使用注入的 Tester 上的方法:

      $I->assertTrue(false);
      

      【讨论】:

      • 谢谢,但我没有那个功能。
      • 是的,正如@sunomad 同时回答的那样,您还需要在您的代码选项/套件配置中启用Asserts 模块,然后您可以使用这些方法:codeception.com/docs/modules/Asserts
      猜你喜欢
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2019-01-08
      • 2020-11-09
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多