按特定顺序运行 PHPUnit 测试 [英] Run PHPUnit Tests in Certain Order

查看:28
本文介绍了按特定顺序运行 PHPUnit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 TestCase 中的测试按特定顺序运行?例如,我想将一个对象的生命周期从创建到使用再到销毁分开,但我需要确保在运行其他测试之前先设置该对象.

Is there a way to get the tests inside of a TestCase to run in a certain order? For example, I want to separate the life cycle of an object from creation to use to destruction but I need to make sure that the object is set up first before I run the other tests.

推荐答案

也许您的测试中存在设计问题.

Maybe there is a design problem in your tests.

通常每个测试都不能依赖于任何其他测试,因此它们可以以任何顺序运行.

Usually each test must not depend on any other tests, so they can run in any order.

每个测试都需要实例化和销毁它运行所需的一切,这将是完美的方法,你永远不应该在测试之间共享对象和状态.

Each test needs to instantiate and destroy everything it needs to run, that would be the perfect approach, you should never share objects and states between tests.

你能更具体地说明为什么 N 个测试需要同一个对象吗?

Can you be more specific about why you need the same object for N tests?

这篇关于按特定顺序运行 PHPUnit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆