Maven에서 테스트 코드 공유
Maven의 다른 모듈의 테스트 코드에 어떻게 의존 할 수 있습니까?
예를 들어 2 개의 모듈이 있습니다.
- 베이스
- 본관
Main의 테스트 사례를 Base의 기본 테스트 클래스로 확장하고 싶습니다. 이것이 가능한가?
업데이트 : 테스트 항아리 만들기와 관련된 적절한 대답을 찾았습니다 .
내가 사용하는 것이 좋습니다 대신 분류의 유형 (참조 : 분류를 ). 그것은 Maven에게 당신이하고있는 일을 좀 더 명확하게 알려줍니다 (그리고 나는 m2eclipse와 q4e가 더 좋아한다는 것을 알았습니다).
<dependency>
<groupId>com.myco.app</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
기본 모듈 제안에 감사드립니다. 그러나이 목적을 위해 새 모듈을 만들지 않습니다.
Surefire Maven 설명서 및 블로그 에서 적절한 답변을 찾았습니다 . " 테스트 클래스를 포함하는 jar 작성 방법 "도 참조하십시오 .
이것은 테스트를 가진 모듈이 코드를 공유 할 수 있도록 jar 플러그인 을 src/test/java
사용하여 jar 파일의 jar 파일을 작성 합니다.
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
위에서 작성된 첨부 된 테스트 JAR을 사용하려면 지정된 테스트 분류 자로 기본 아티팩트에 대한 종속성을 지정하십시오.
<project>
...
<dependencies>
<dependency>
<groupId>com.myco.app</groupId>
<artifactId>foo</artifactId>
<version>1.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
...
</project>
우리는 테스트 코드를 src / main / java로 maven 프로젝트를 만들고 프로젝트에 다음과 같은 종속성을 추가하여이를 해결했습니다.
<dependency>
<groupId>foo</groupId>
<artifactId>test-base</artifactId>
<version>1</version>
<scope>test</scope>
</dependency>
Yep ... just include the Base module as a dependency in Main. If you're only inheriting test code, then you can use the scope tag to make sure Maven doesn't include the code in your artifact when deployed. Something like this should work:
<dependency>
<groupId>BaseGroup</groupId>
<artifactId>Base</artifactId>
<version>0.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
참고URL : https://stackoverflow.com/questions/174560/sharing-test-code-in-maven
'Programming' 카테고리의 다른 글
MySQL 루트 비밀번호를 제거하는 방법 (0) | 2020.05.20 |
---|---|
Java로 객체 배열 만들기 (0) | 2020.05.20 |
Javascript Regex : 정규식 안에 변수를 넣는 방법? (0) | 2020.05.20 |
ab 부하 테스트 (0) | 2020.05.20 |
“Microsoft Advertising SDK”Visual Studio 확장을 제거하는 방법은 무엇입니까? (0) | 2020.05.20 |