Pregunta

I have my own source set that uses some of the main sources:

sourceSets {
    special {
            java {
                source main.java
            }
    }

I made sure that it can be compiled and run properly:

configurations {

    specialCompile.extendsFrom(compile)
    specialRuntime.extendsFrom(runtime)

}

And have my own test task for it:

task heavyTest(type: Test) {
    useTestNG()         
    testClassesDir  = project.sourceSets.special.output.classesDir
    testSrcDirs    += project.sourceSets.special.java.srcDirs.toList()
}

Special source contains test methods in class org.me.ImportantTests

Compilation works and tests runs succesfully in eclipse as well, yet when i try to execute heavyTest task from gradle it fails

01:18:23.360 [ERROR] [system.err] 01:18:23.357 [ERROR] [system.err] [TestNG] [ERROR] No test suite found. Nothing to run
01:18:23.488 [QUIET] [system.out] 01:18:23.486 [QUIET] [system.out] Usage: <main class> [options] The XML suite files to run

running with -d reveals that gradle encountered ClassNotFoundException:

01:18:23.559 [DEBUG] [TestEventLogger]         Caused by:
01:18:23.559 [DEBUG] [TestEventLogger]         org.gradle.api.GradleException: Could not load test class 'org.me.ImportantTests'.
01:18:23.560 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.processTestClass(TestNGTestClassProcessor.java:67)
01:18:23.561 [DEBUG] [TestEventLogger]             at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
01:18:23.561 [DEBUG] [TestEventLogger]             ... 21 more
01:18:23.561 [DEBUG] [TestEventLogger]
01:18:23.562 [DEBUG] [TestEventLogger]             Caused by:
01:18:23.563 [DEBUG] [TestEventLogger]             java.lang.ClassNotFoundException: org.me.ImportantTests

It looks like the .class file is not in the classpath... but I set testClassesDir properly and the class is exactly where it shold be (/org/me/ImportantTests.class)! What is wrong with this task?

¿Fue útil?

Solución

Ok, I noticed i can fix this in the following way:

task integTest2(type: Test) {
    useTestNG()
    testClassesDir  = project.sourceSets.special.output.classesDir
    classpath = classpath.plus(files(testClassesDir))
    testSrcDirs    += project.sourceSets.special.java.srcDirs.toList()
}

This works, but looks quite... stupid. Why do I need to tell the test task, that directory with classes to test should be on the classpath? "Please test classes that are in that directory. Oh, by the way, to load them, try looking in the directory in which they are". Am I doing something wrong?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top