2010-06-15 5 views
4

우리는 MySQL을 프로덕션에서 사용하고 Derby는 단위 테스트를 위해 사용합니다. 우리의 pom.xml 파일 복사 테스트 이전의 persistence.xml의 더비 버전 및 MySQL 버전으로 대체가에서 준비 패키지 단계 :mvn 부두를 방지하는 방법 : 테스트 단계 실행에서 실행 하시겠습니까?

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.3</version> 
    <executions> 
    <execution> 
    <id>copy-test-persistence</id> 
    <phase>process-test-resources</phase> 
    <configuration> 
    <tasks> 
     <!--replace the "proper" persistence.xml with the "test" version--> 
     <copy 
     file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test" 
     tofile="${project.build.outputDirectory}/META-INF/persistence.xml" 
     overwrite="true" verbose="true" failonerror="true" /> 
    </tasks> 
    </configuration> 
    <goals> 
    <goal>run</goal> 
    </goals> 
    </execution> 
    <execution> 
    <id>restore-persistence</id> 
    <phase>prepare-package</phase> 
    <configuration> 
    <tasks> 
     <!--restore the "proper" persistence.xml--> 
     <copy 
     file="${project.build.outputDirectory}/META-INF/persistence.xml.production" 
     tofile="${project.build.outputDirectory}/META-INF/persistence.xml" 
     overwrite="true" verbose="true" failonerror="true" /> 
    </tasks> 
    </configuration> 
    <goals> 
    <goal>run</goal> 
    </goals> 
    </execution> 
    </executions> 
</plugin> 

문제는 내가 MVN 부두를 실행하면 것을,이다 : 그것은를 실행 실행 jetty를 시작하기 전에 persistence.xml 파일 복사 작업을 테스트하십시오. 배포 버전을 사용하여 실행되기를 원합니다. 이 문제를 어떻게 해결할 수 있습니까?

답변

2

목표 을 실행하기 전에 수명주기 단계 test-compile의 실행을 호출합니다. 따라서 실행 테스트를 건너 뛰어도 아무 것도 바뀌지 않습니다.

copy-test-persistence 실행을 test-compile의 후반에서 test 이전의 수명주기 단계로 바인드해야합니다. 그리고 후보자는 12 명이 아니라 단지 하나뿐입니다 : process-test-classes.

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.3</version> 
    <executions> 
    <execution> 
    <id>copy-test-persistence</id> 
    <phase>process-test-classes</phase> 
    <configuration> 
    <tasks> 
     <!--replace the "proper" persistence.xml with the "test" version--> 
     <copy 
     file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test" 
     tofile="${project.build.outputDirectory}/META-INF/persistence.xml" 
     overwrite="true" verbose="true" failonerror="true" /> 
    </tasks> 
    </configuration> 
    <goals> 
    <goal>run</goal> 
    </goals> 
    </execution> 
    ... 
    </executions> 
</plugin> 
5

-Dmaven.test.skip=true or -DskipTests=true in the command line을 추가해보십시오. 예를 들어

mvn -DskipTests=true jetty:run ... 

프로세스 테스트 자원 단계를 건너 뛸 지 확실하지 않습니다.

테스트 건너 뛰기에 대한 추가 정보 is available in the Surefire plugin documentation.

+1

만약 내가 이미 테스트를 언급하는 것을 잊었다하지만, 도움이되지 않습니다 개념적 어쩌면 이상적인 아니지만, 그것은 적어도 더 나쁜 옵션, 그리고 그것을 작동합니다

. – tputkonen