본문 바로가기

빌드관리시스템/Maven

[Maven] 특정 Test만 따로 수행하기

Java에서 jUnit으로 일반적으로 테스트코드를 구현하기 때문에 대부분 junit으로 디버그를 수행하거나 Maven test로 TC를 수행합니다.

이 때 Maven에 전달한 환경설정에 맞춰 특정 테스트만 따로 수행하고 싶을 때가 있습니다. 

그럴땐... Maven 명령어에 -Dtest=패키지.클래스명#메서드명 를 이용합니다.


어 그런데 저의 경우 모듈이 1개가 아닌 상위모듈, 하위모듈로 구성된 Maven이었습니다.


parent

ㄴ child-api

ㄴ child-batch


라고 프로젝트가 구성되어있다면...


아마 이미 Maven이 구축된 상태라면 -pl 옵션을 함께 쓰고 있을것 같습니다.


명령어

mvn -pl=parent,child-batch clean compile test -P alpha -U -Dtest=com.sample.maven.UtilTest#test2 -DfailIfNoTests=false


수행 결과

Running com.sample.maven.UtilTest

Profile :  alpha데이터

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in com.sample.maven.UtilTest


-DfailIfNoTests=false 은 parent의 test도 함께 수행되는듯한데(추측?) 그 때마다 실패가 발생해서 제대로된 TC를 수행할 수 없어서 무시처리하는 옵션입니다.



참고 

- http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

- https://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven