2015-01-26 5 views
6

프로젝트에서 Gradle과 TestNG를 사용하기 시작 했으므로 테스트에 실패해도 실제로 빌드가 실패하는지 확인하고 있습니다. 나는 그렇지 않다는 것을 알기에 꽤 놀랐다. 테스트가 선택되어 올바르게 컴파일되므로 클래스 파일이 표시됩니다. 또한 나는 뛰기의보고를 얻는다, 그러나 0의 시험을 말한다 (예상 된 2). gradle clean test -i을 실행하면 나에게주는 다음Gradle은 컴파일하지만 TestNG 테스트를 실행하지 않습니다.

:contentplatform-service:compileTestJava (Thread[Daemon worker Thread 7,5,main]) 
started. 
:contentplatform-service:compileTestJava 
Executing task ':contentplatform-service:compileTestJava' (up-to-date check took 
0.08 secs) due to: 
    Output file D:\Dev\contentplatform-service\build\classes\test has changed. 
    Output file D:\Dev\contentplatform-service\build\dependency-cache has changed. 

    Output file D:\Dev\contentplatform-service\build\classes\test\nl\xillio\conten 
tplatform\service\SuperSimpleTest.class has been removed. 
All input files are considered out-of-date for incremental task ':contentplatfor 
m-service:compileTestJava'. 
Compiling with JDK Java compiler API. 
:contentplatform-service:compileTestJava (Thread[Daemon worker Thread 7,5,main]) 
completed. Took 0.229 secs. 
:contentplatform-service:processTestResources (Thread[Daemon worker Thread 7,5,m 
ain]) started. 
:contentplatform-service:processTestResources 
Skipping task ':contentplatform-service:processTestResources' as it has no sourc 
e files. 
:contentplatform-service:processTestResources UP-TO-DATE 
:contentplatform-service:processTestResources (Thread[Daemon worker Thread 7,5,m 
ain]) completed. Took 0.001 secs. 
:contentplatform-service:testClasses (Thread[Daemon worker Thread 7,5,main]) sta 
rted. 
:contentplatform-service:testClasses 
Skipping task ':contentplatform-service:testClasses' as it has no actions. 
:contentplatform-service:testClasses (Thread[Daemon worker Thread 7,5,main]) com 
pleted. Took 0.001 secs. 
:contentplatform-service:test (Thread[Daemon worker Thread 7,5,main]) started. 
:contentplatform-service:test 
Executing task ':contentplatform-service:test' (up-to-date check took 0.049 secs 
) due to: 
    Output file D:\Dev\contentplatform-service\build\test-results\binary\test has 
changed. 
    Output file D:\Dev\contentplatform-service\build\test-results has changed. 
    Output file D:\Dev\contentplatform-service\build\reports\tests has changed. 
Finished generating test XML results (0.0 secs) into: D:\Dev\contentplatform-ser 
vice\build\test-results 
Generating HTML test report... 
Finished generating test html results (0.014 secs) into: D:\Dev\contentplatform- 
service\build\reports\tests 
:contentplatform-service:test (Thread[Daemon worker Thread 7,5,main]) completed. 
Took 0.194 secs. 

SuperSimpleTest.java :

package nl.xillio.contentplatform.service; 

import org.testng.Assert; 
import org.testng.annotations.BeforeClass; 
import org.testng.annotations.Test; 

@Test 
public class SuperSimpleTest { 

    @BeforeClass 
    public void setUp() { 
     // code that will be invoked when this test is instantiated 
    } 

    @Test 
    public void testTest() { 
     Assert.assertEquals(true, true); 
    } 
} 

build.gradle가 포함

test { 
    // enable TestNG support (default is JUnit) 
    useTestNG() 
    scanForTestClasses = false 
    include '**/*' 

    testLogging { 
     showStandardStreams = true 

     // log results to "build/test-results" directory 
     exceptionFormat "full" 
     events "started", "passed", "skipped", "failed", "standardOut", "standardError" 
    } 
} 

나는 이미이 주제에 대해 other questions을 확인해 보니 대안으로 scanForTestClasses = false을 사용하는 힌트를 발견했습니다 (https://issues.gradle.org/browse/GRADLE-1682 참조). 그러나이 문제는 관련이없는 것처럼 보입니다. 다른 멍청한 실수를하고 있습니까? SuperSimpleTest를 실행하려면 어떻게해야합니까?

UPDATE :

+0

공유 샘플 프로젝트를 GH에하시기 바랍니다. 도움이 될 것입니다. – Opal

+0

죄송합니다.이 코드를 사용하면 좋겠지 만 그렇게 할 수는 없습니다. 나는 정말로 내가 바보처럼 단순한 것을 잊거나 간과하지 않고있는 이중 점검을 찾고있다. – titusn

+0

나는 최근에 유사한 문제를 해결했습니다 : http://stackoverflow.com/questions/28008918/gradle-not-running-testng-tests-even-with-test-usetestng/28077602#28077602, 그러나 @amorfis는 문제를 재생산합니다. 여기에 어려울 수도 있습니다 :/ – Opal

답변

14

Gradle complains about JUnit version on TestNG task 그것은 참으로 바보 같은 멍청한 실수를했다 : 나는 결과로 흥미로운 오류가 특정 테스트를 실행 Gradle을 강요했습니다. 우리는 마스터 프로젝트와 코드 및 테스트가 포함 된 동일한 레벨의 여러 폴더가있는 다중 프로젝트 설정을 사용하고 있습니다. build.gradle 실수로 TestNG를 사용하기 위해 마스터 프로젝트 만 구성했습니다. 해결책은 allprojects 또는 subprojects 클로저 내에 테스트 타겟을 포함시키는 것입니다. 그래서 여기 What is the difference between allprojects and subprojects

을 작업 build.gradle입니다 : 어떤 여기에 설명

def mainClassName = 'nl.xillio.contentplatform.view.Run' 


// Load settings for all projects including master and subprojects 
allprojects { 
    apply plugin: 'java' 
    apply plugin: 'eclipse' 

    version '0.1' 

    repositories { 
     mavenCentral() 
     maven { 
      url 'http://mvnrepository.com/maven2' 
     } 
     maven { 
      url 'http://download.java.net/maven/2' 
     } 
    } 
} 

// Load the dependencies for all subprojects (layers) 
subprojects { 
    dependencies { 
    //to do: move these to the correct subprojects 
     compile 'javax.inject:javax.inject:1' 
     compile 'org.springframework:spring-context:4.1.4.RELEASE' 
     compile 'org.springframework:spring-core:4.1.4.RELEASE' 
     compile 'org.springframework:spring-beans:4.1.4.RELEASE' 
     compile 'commons-logging:commons-logging:1.2' 
     testCompile 'org.springframework:spring-test:4.1.4.RELEASE' 
     testCompile 'org.testng:testng:6.1.1' 
    } 

    test { 
     // enable TestNG support (default is JUnit) 
     useTestNG() 
    } 
} 

// Resolve the dependencies between the layers in the individual project's build.gradle files 
// add ONLY specific per project behaviour of the GLOBAL build here: 

project(':contentplatform-web') { 
} 

project(':contentplatform-service') { 
} 

project(':contentplatform-dao') { 
} 

// Return a list of all the external libraries 
def getLibraries() { 
    return configurations.runtime.filter{!it.name.startsWith('contentplatform')} 
} 

// Copy all the libraries to a libs folder 
task copyLibraries(type: Copy) { 
    group 'Content Platform' 
    description 'Copy all the external libraries to the /libs folder.' 

    destinationDir file('./build/') 

    into('libs/') { 
     from getLibraries() 
    } 
} 

// Perform the build task before building the big jar 
jar { 
    group 'Content Platform' 
    description 'Package all the layers and dependencies into a big jar.' 

    // The libraries are required to build 
    dependsOn(copyLibraries) 

    // The final big jar needs all the layers 
    dependencies { 
     compile project(':contentplatform-web'), project(':contentplatform-dao'), 
      project(':contentplatform-service'), project(':contentplatform-model') 
    } 
    // Create a MANIFEST.MF file, the main class file is in the web layer 
    manifest { 
     attributes 'Implementation-Title': 'Content Platform', 
      'Implementation-Version': version, 
      'Built-By': System.getProperty('user.name'), 
      'Built-Date': new Date(), 
      'Built-JDK': System.getProperty('java.version'), 
      'Class-Path': getLibraries().collect{'../libs/' + it.getName()}.join(' '), 
      'Main-Class': mainClassName 
    } 

    // Include the layers in the fat jar 
    from(configurations.compile.filter{it.name.startsWith('contentplatform')}.collect{it.isDirectory() ? it : zipTree(it) }) { 
     exclude "META-INF/*.SF" 
     exclude "META-INF/*.DSA" 
     exclude "META-INF/*.RSA" 
    } 

    // Save the fat jar in the root of the folder instead of in build/libs 
    destinationDir file('.') 
} 
관련 문제