【问题标题】:Running an individual JUnit test from separate class [duplicate]从单独的类运行单独的 JUnit 测试 [重复]
【发布时间】:2013-06-13 23:03:28
【问题描述】:

我正在尝试从可以编译和报告信息的单独类中运行测试。但是,我在运行单个测试时遇到了困难。

我试过了:

for (int i = 0; i < testRuns; i++) {
  JUnitCore.runClasses(InternetExplorerTestClass.class, MozillaFirefoxTestClass.class, GoogleChromeTestClass.class);
}

但这限制了我对结果和报告数据的控制。

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

【问题讨论】:

    标签: java unit-testing junit


    【解决方案1】:

    看起来你正在做类似 Selenium 测试的事情?如果你使用 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'    
    }
    

    This is taken from a example project I wrote here.

    【讨论】:

      猜你喜欢
      • 2018-02-08
      • 2018-04-19
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2017-04-20
      相关资源
      最近更新 更多