Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从单独的类运行单独的JUnit测试_Java_Unit Testing_Junit - Fatal编程技术网

Java 从单独的类运行单独的JUnit测试

Java 从单独的类运行单独的JUnit测试,java,unit-testing,junit,Java,Unit Testing,Junit,我试图从一个单独的类运行测试,在这个类中可以编译和报告信息。然而,我在运行单独的测试时遇到了困难 我试过: for (int i = 0; i < testRuns; i++) { JUnitCore.runClasses(InternetExplorerTestClass.class, MozillaFirefoxTestClass.class, GoogleChromeTestClass.class); } for(int i=0;i

我试图从一个单独的类运行测试,在这个类中可以编译和报告信息。然而,我在运行单独的测试时遇到了困难

我试过:

for (int i = 0; i < testRuns; i++) {
  JUnitCore.runClasses(InternetExplorerTestClass.class, MozillaFirefoxTestClass.class, GoogleChromeTestClass.class);
}
for(int i=0;i
但这限制了我对结果和报告数据的控制


如何从测试套件中运行单个测试?提前谢谢你。

看起来你好像在做硒测试?如果您使用Gradle作为构建工具,您可以通过使用“include”过滤器选项轻松运行一个特定的测试,如下所示。(您也可以使用Ant、SBT或Maven执行类似的操作)。就我个人而言,我认为使用构建工具选择要运行的测试比编写代码来运行某些类更优雅

tasks.withType(Test) {

    jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
    maxParallelForks = 4

    // System properties passed to tests (if not http://localhost:8001/index.html)
    systemProperties['testProtocol'] = 'http'
    systemProperties['testDomain'] = 'djangofan.github.io'
    systemProperties['testPort'] = 80
    systemProperties['testUri'] = '/html-test-site/site'
    systemProperties['hubUrl'] = 'localhost'
    systemProperties['hubPort'] = '4444'

}

task runParallelTestsInFirefox(type: Test) {
    description = 'Runs all JUnit test classes in parallel threads.'
    include '**/TestHandleCache*.class'
    testReportDir = file("${reporting.baseDir}/ParallelTestsFF")
    testResultsDir = file("${buildDir}/test-results/ParallelTestsFF")

    // System properties passed to tests
    systemProperties['browserType'] = 'firefox'

    // initial browser size and position
    systemProperties['windowXPosition'] = '100'
    systemProperties['windowYPosition'] = '40'
    systemProperties['windowWidth'] = '400'
    systemProperties['windowHeight'] = '600'    
}