假设我有一个类,它只对特定的路由执行某些操作,这些路由名称存储在service.yaml
中
parameters:
supported_routes: ['route1', 'route2']
我想写几个测试案例:
- testIgnoreRoute 1 IfRouteNotSupported-我想将
supported_routes
列表更改为排除route1
- testIgnoreRoute 2 IfRouteNotSupported-我想将
supported_routes
列表更改为排除route2
- testPerformanceIfRoute 1 Supported-我希望在
supported_routes
中包含route1
- testPerformanceIfRoute 2Supported-我希望在
supported_routes
中包含route2
我怎么能这么做呢?由于容器被冻结,不允许动态更改容器参数。可以使用测试service.yaml
覆盖service.yaml
,但在这种情况下,即使它可以与主列表不同,它仍然是所有测试的相同列表。此外,可以将该列表存储在env中,但我不认为这是一个好主意,因为我不希望它在一个真实的应用程序中依赖于env。
我知道你可以告诉我为什么不写一个单元测试,模拟你需要的东西,这不像我的真实的应用程序那么容易,第三方库使用列表作为库配置的一部分,所以它应该是集成/功能测试。
1条答案
按热度按时间qzwqbdag1#
我现在唯一能想到的是,我不知道我是否正确理解了你的问题。
您可以为测试定义不同的环境,并相应地调用它们。
service.yaml
使用
APP_ENV=<envname> php bin/phpunit --filter ServiceTest
启动相应的测试。更新
将APP_ENV设置为动态。