1

I am trying to run tests from a separate class where information can be compiled and reported. I am having difficulty running individual tests, however.

I tried:

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

but that limits the control I have over the results and reporting the data.

How do I run a single test from a test suite? Thank you in advance.

Ross Verry
  • 115
  • 8

1 Answers1

0

It almost looks like you are doing something like a Selenium test? If you use Gradle as your build tool, you can easily run one specific test by using the "include" filter option like so. (You could do something similar with Ant, SBT, or Maven as well). Personally, I think using the build tool to pick the tests to run is more elegant than writing code to run certain classes.

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.

djangofan
  • 28,471
  • 61
  • 196
  • 289