vendredi 14 décembre 2018

Gradle how to use filter.includeTestsMatching to run tests from failedtest.log file

I am using gradle, junit,selenium and intellij. I am working on custom e2e library. The goal is to create a gradle task to run failed tests only. I have created a testlistener which writes failed test class and method names to failedtest.log file after every test. I created a gradle task to run all of the failed test in the logs, but it is throwing an error message: No tests found for given includes:

 /Users/Desktop/local_apps/e2e/build/test-results/failedTestClasses.log 
 (filter.includeTestsMatching) 

My listener looks like:

@Override
public void afterTestExecution(TestContext testContext) throws Exception {
    if (testContext.getTestException() != null) {
        File failedTestFile = new File("build/test-results/failedTestClasses.logs");
        String failedTests = testContext.getTestClass().getName() + "," +  testContext.getTestMethod().getName() + "\n";
        FileUtils.writeStringToFile(failedTestFile, failedTests, "utf-8", true);
    } else {
        return;
    }
 }

My gradle task looks like:

task testFailedTests(type: Test) {
def failedTests = []
def failureLogs = "$buildDir/test-results/failedTestClasses.log"
if (failureLogs.length() > 0) {
    failureLogs.eachLine { line ->
        def tokens = line.split(",")
        failedTests << tokens[0]
    }
}
filter {
    failedTests.each {
        includeTestsMatching "${it}"
    }
}}

My failedTestClasses.log file looks like following after running a test when test fails:

 testClassName,testMethodName

I would appreciate the help. I am really new to java and still trying to learn syntax.

Aucun commentaire:

Enregistrer un commentaire