我有一些常规测试用例(即扩展 GroovyTestCase
(版本 1.8.2)的类)。例如
class TestCaseA extends GroovyTestCase {void testA1() {...} void testA2() {...}} class TestCaseB extends GroovyTestCase {void testB1() {...} void testB2() {...}}
我想对测试(测试方法)进行分组。
例如,
group X: TestCaseA.testA1, TestCaseB.testB1, TestCaseB.testB2, group Y: TestCaseB.testB2 group Z: TestCaseA.testA1, TestCaseA.testA2
为了实现这样的分组,我想添加注释。 (我可以更改测试源)。
例如:
class TestCaseA extends GroovyTestCase { @TestGroup (TestGroup.X, TestGroup.Z) void testA1() {...} @TestGroup (TestGroup.Z) void testA2() {...} }
现在我想编写一个自定义 JUnit Runner
,它接收“测试组”(例如作为命令行参数或环境变量)并且只运行用这些组注释的测试方法。
有意义吗?有哪些选择?如何实现自定义 JUnit Runner?
最佳答案
可能不是您要找的东西,但另一种方法是使用支持开箱即用的组概念的 TestNG http://testng.org/doc/documentation-main.html#test-groups .应该可以与 Groovy 一起正常工作:http://groovy.codehaus.org/Using+TestNG+with+Groovy
我知道这对你没用,如果你坚持使用 JUnit...
关于unit-testing - 如何对常规测试进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8743356/