我的项目根文件夹上有一个codeception.yml。这有一个包含配置指令,用于我的不同模块的其他欺骗yml。
include:
- tests/Modules/*
这将在这里作为多个应用程序设置来描述。
https://codeception.com/docs/08-Customization#One-Runner-for-Multiple-Applications
这些子信任有不同的套件吐露,在他们自己的codeception.yml中描述,就像在
测试/模块/前端/代码欺骗.
suites:
Presentation:
path: Presentation
class_name: PresentationTester
modules:
...
问题:在我的项目根文件夹中,我无法为所有包含的模块运行一个特定的套件
vendor/bin/codecept run Presentation
上面写着
找不到
套房的“演示文稿”
运行指向某个配置的它确实有效。
vendor/bin/codecept run Presentation -c tests/Modules/Frontend
但它只运行这一个模块。我想用一个命令运行所有模块的特定套件。
运行一个组(-g)也是有效的,因此这表明信任的加载是正确的。
为什么这不适用于套房?所有的信任都包括在我的主要yml,所以套房必须找到在我的意见。
当没有套间可以从中心点运行时,有这样的设置有什么意义呢?
有什么想法吗?
发布于 2020-09-29 23:19:05
更新:发现了一些问题和解决方案,请参考我的答案的结尾。
昨天我发现自己和你的处境一样。我是从以套件为中心的结构中重构我们的测试套件的。
tests/
unit/
Module1/
Module2/
... (more modules)
integration/
Module1/
Module2/
... (more modules)
... (more suites)
一个新的以模块为中心的结构,如
tests/
Module1/
Unit/
Integration/
... (more suites)
Module2/
Unit/
Integration/
... (more suites)
... (more modules)
然而,在我看来,However并不支持这一点。在搜索和调试code代码之后,我找到了这些信息。
解决办法
在这里,https://github.com/Codeception/Codeception/issues/5486用户LeeShan8似乎发出了同样的问题,用户vertexvaar谈到了他制作的修补程序,该修补程序提供了一个--recurse-include
选项,可以在每个子模块中运行特定的套件(可以从那里下载补丁)。
所以我从顶点库搜索了公关,想知道他的补丁是怎么回事。这是PR https://github.com/Codeception/Codeception/pull/5737,但由于SamMousa的不活动而关闭。
SamMousa指出了一个解决办法:--skip
选项。
如果您想在每个子模块中从unit
套件运行测试,可以这样做:
codecept run -s suite1 -s suite2 ...
其中suite1
,suite2
.都是不包括unit
的测试套件。如果您跳过了所有其他套件,case将在每个子模块中运行其余的套件(在本例中是unit
)。
我的解决方案
我真的不想通过列出unit
选项中的所有其他套件来运行--skip
套件。它太无聊了,写得很慢,而且容易出错。
我确实希望指定codecept run unit
,并看到所有单元测试逐个模块地运行。所以我创建了一个小补丁(https://gist.github.com/mpallante/101b1508ffc5a2c4bf30d3344437ca0b)来修复这种行为。
它与vertexvar中的类似,但为了保持简单,我没有添加新选项。它只从每个子模块运行指定的套件。
我还使用composer-patches
(https://github.com/cweagans/composer-patches)实现了补丁程序的自动化。
我安装了composer-patches
composer require cweagans/composer-patches
然后将补丁放在patches/allow-codeception-run-suites-from-submodules.patch
中,并将composer.json
更改为包含修补程序(在"extra"
部分中):
...
"extra": {
...
"patches": {
"codeception/codeception": {
"Allow Codeception to run suites from submodules": "patches/allow-codeception-run-suites-from-submodules.patch"
}
}
},
...
最后,我运行了composer update codeception/codeception
:它将删除协同欺骗,重新安装它,并应用修补程序:
$ php which composer update codeception/codeception
Gathering patches for root package.
Removing package codeception/codeception so that it can be re-installed and re-patched.
- Removing codeception/codeception (4.1.7)
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing codeception/codeception (4.1.7): Loading from cache
- Applying patches for codeception/codeception
patches/allow-codeception-run-suites-from-submodules.patch (Allow Codeception to run suites from submodules)
注意事项
请注意,这是解决方案似乎在我的情况下,但它没有充分测试。我通常以极少数的方式运行conflicts (单个套件、所有套件、单个测试文件),所以不知道是否存在冲突。
然而,这可能是一个起点。
也许在将来的某个时候,我可以把这个补丁贡献给项目本身。
更新
我发现了一个小问题:当一个套件在子模块中定义,而不是全局定义时,codecept run
会跳过它。
我通过这样在全局codeception.yml
配置文件中定义套件来解决这个问题:
include:
- modules/*/Tests
suites:
integration:
unit:
paths:
...
然后,在每个子模块中,我定义了一个./modules/Mod1/Tests/codeception.yml
文件,如下所示:
suites:
unit:
path: ./Unit
modules:
enabled:
- Asserts
- \Helper\Unit
integration:
path: ./Integration
modules:
enabled:
- \Helper\Integration
namespace: Modules\Mod1\Tests
paths:
tests: .
output: ../../../tests/_output
support: ../../../tests/_support
data: ./_data
希望这能帮上忙。
https://stackoverflow.com/questions/62447343
复制