简体   繁体   English

带套件的Junit Test Runner

[英]Junit Test Runner with Suite

Is it possible to get a TestRunner to run a Test Suite that's been created programmatically? 是否有可能让TestRunner运行以编程方式创建的测试套件?

The Block4JunitTestRunner for example takes the Suite class as the constructor argument. 例如,Block4JunitTestRunner将Suite类作为构造函数参数。 However, I can't do this since the Suite isn't a concrete Suite. 但是,我不能这样做,因为套件不是具体套件。 I dynamically add TestCases to a TestSuite and now I need a TestRunner to run it so im able to get Junit report the test failures/success/errors as normal. 我动态地将TestCases添加到TestSuite,现在我需要一个TestRunner来运行它,所以我能够让Junit正常报告测试失败/成功/错误。 (

Thanks. 谢谢。

SuiteRunner SuiteRunner

BlockJunit4ClassRunnerForInstance BlockJunit4ClassRunnerForInstance

Example Suite 示例套件

This suite runner requires that you provide a static method returning a list of test instances eg 此套件运行器要求您提供返回测试实例列表的静态方法,例如

public static List<Object> testInstances(){
    ArrayList<Object> objects = new ArrayList<Object>();
    ..
    return objects;
}

The original behaviour of the block runner is to create a new instance per test method, so you might need to do more work in the setup to keep the tests independent. 块运行器的原始行为是为每个测试方法创建一个新实例,因此您可能需要在设置中做更多工作以保持测试独立。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM