2012-03-07 19 views
14

Próbuję migrować z kompilacji Ant do Gradle w moim projekcie. Istnieje kilka przypadków testowych (podklasy junit.framework.TestCase) i kilka zestawów testów (podklasy junit.framework.TestSuite). Gradle automatycznie wyłapuje wszystkie przypadki testowe (podklasy junit.framework.TestCase), które mają być uruchomione, ale nie pakiety (podklasy junit.framework.TestSuite).Jak uruchomić Junit TestSuites z gradle?

Prawdopodobnie mógłbym obejść, dzwoniąc do ant.junit, aby go uruchomić. Ale czuję, że powinien być rodzimy łatwy sposób, aby zmusić go do wybierania i ucieczki. Nie mogłem znaleźć niczego w dokumencie. Czy czegoś brakuje?

+1

Wydajesz się być sprzeczne siebie ... mówisz, że "Gradle automatycznie wybrał wszystkie przypadki testowe do uruchomienia". Problem polega na tym, że je skompilował, ale ich nie uruchomił? Proszę o wyjaśnienie. –

+0

@c_maker: Edytowałem tekst, aby poprawić czytelność. Dzięki za wskazanie. – James

Odpowiedz

13

To było trudne dla mnie, aby dowiedzieć się, ale tutaj jest przykład:

// excerpt from https://github.com/djangofan/WebDriverHandlingMultipleWindows 
package webdriver.test; 
import http.server.SiteServer; 
import java.io.File; 
import java.io.IOException; 
import org.junit.AfterClass; 
import org.junit.BeforeClass; 
import org.junit.runner.RunWith; 
import org.junit.runners.Suite; 

@RunWith(Suite.class) 
@Suite.SuiteClasses({ TestHandleCacheOne.class, TestHandleCacheThree.class, TestHandleCacheThree.class }) 
public class SuiteOne extends MultiWindowUtils { 

    public static SiteServer fs; 

    @BeforeClass 
    public static void setUpSuiteOne() { 
     File httpRoot = new File("build/resources/test"); 
     System.out.println("Server root directory is: " + httpRoot.getAbsolutePath()); 
     int httpPort = Integer.parseInt("8080"); 
     try { 
      fs = new SiteServer(httpPort , httpRoot); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     initializeBrowser("firefox"); 
     System.out.println("Finished setUpSuiteOne"); 
    } 

    @AfterClass 
    public static void tearDownSuiteOne() { 
     closeAllBrowserWindows(); 
     System.out.println("Finished tearDownSuiteOne"); 
    } 

} 

I build.gradle podobny do tego:

apply plugin: 'java' 
apply plugin: 'eclipse' 
group = 'test.multiwindow' 

ext { 
    projTitle = 'Test MultiWindow' 
    projVersion = '1.0' 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+' 
    compile group: 'junit', name: 'junit', version: '4.+' 
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+' 
} 

task testGroupOne(type: Test) { 
    //include '**/*SuiteOne.*' 
    include '**/SuiteOne.class' 
    reports.junitXml.destination = "$buildDir/test-results/SuiteOne") 
    reports.html.destination = "$buildDir/test-results/SuiteOne") 
} 

task testGroupTwo(type: Test) { 
    //include '**/*SuiteTwo.*' 
    include '**/SuiteTwo.class' 
    reports.junitXml.destination = "$buildDir/test-results/SuiteTwo") 
    reports.html.destination = "$buildDir/test-results/SuiteTwo") 
} 
+0

Muszę powiedzieć, że odkąd opublikowałem tę odpowiedź, DSL dla konfigurowania testów jednostkowych nieco się zmieniło. Tak więc, uważaj. – djangofan

Powiązane problemy