在Codeception中,在Unit.php和UnitTester.php中定义辅助方法有什么区别?

问题描述 投票:0回答:1

在Codeception单元测试中,publicUnit.php中定义的所有UnitTester.php方法都在$this->tester中可用。

一些Codeception单元测试的支持文件:

tests/_support/_generated/UnitTesterActions.php
tests/_support/Helper/Unit.php
tests/_support/UnitTester.php

$this->testerUnitTester的实例。UnitTester.phpuse_generated\UnitTesterActions本身在初始化测试时将Unit.php中的方法嵌入其中。除了IDE在运行测试之前无法解析$this->tester中的方法之外,还有什么区别?是否有最佳实践,还是仅仅是口味问题?为什么有两种不同的方式来做同一件事?

codeception
1个回答
0
投票

实际上我不知道为什么可以向UnitTester类添加方法,但是它们的重用性较差。

通过将它们作为模块启用,可以在不同的套件中使用Helper类中定义的方法。没有理由将助手名称限制为套件名称,可以使用专门命名的助手,例如Helper \ Authentication,Helper \ Rainbow等。

© www.soinside.com 2019 - 2024. All rights reserved.