如果其他测试失败,我可以跳过 Junit 测试吗?

我正在使用 Junit 通过 Seleniun WebDriver 运行测试.我正在尝试将我的测试分成功能区域以便更好地报告错误.我创建了测试来测试页面加载/将文档移动到其他工作流程.如果页面加载测试失败,或者工作流程移动失败,我想跳过后续的页面/工作流程测试.

I'm using Junit to run tests with Seleniun WebDriver. I'm trying to split up my tests into function area for better error reporting. I've created tests to test Page load/moving documents to other workflows. If a page load test fails, or a workflow move fails I want to skip the subsequent page/workflow tests.

如果测试 A 失败,我如何跳过班级中的其余测试或在班级 B 中运行测试?

if a Test A fails how can I skip either the rest of the tests in the class or running tests in Class B?

注意:我意识到我要问的是UNIT TESTS 的不好的做法*".但是,我实际上将 Junit 用于 Integration 和/或 Automation 测试.(取决于您的定义.)我已经找到 @Suite.SuiteClasses@FixMethodOrder 来订购我的测试类和测试方法.我试图命令它们在逻辑上运行,首先测试页面加载,然后将页面的每个功能作为单独的测试.一些功能,将信息移动到其他页面,意味着其他类.我的 1 节课可能需要 1/2 多小时才能完成.如果 pre-req 测试失败,我想短路依赖"测试,以便更快地得到我的结果/报告.

NOTE: I realize what I'm asking is "bad Practice* for UNIT TESTS. However, I'm actually using Junit for Integration and/or Automation Testing. (Depending on your definition.) I've already found @Suite.SuiteClasses, and @FixMethodOrder to order my test classes and test methods. I'm trying to order them to run logically, testing the page load, first, then each feature of the page as a seperate test. Some of the features, move the information to other pages, meanining other classes. 1 of my classes can take over 1/2 hour to finish. If the pre-req tests fail, I'd like to short circuite the "Dependent" tests, in order to get my results/report sooner.

推荐答案

我建议你切换到TestNG.检查this.

I suggest you switching to TestNG. Check this out.

顺便说一句:当我使用 Java 工作时 - 差不多一年前 - 我没有为 JUnit 找到这样的解决方案.

Btw:When I used to work with Java - almost one year ago - I didn't find such a solution for JUnit.

相关文章