메이븐 솔루션과 확실한 솔루션의 두 가지 옵션이 있습니다. 가장 적은 결합 솔루션은 pre-integration-test
및 post-integration-test
단계에서 플러그인을 실행하는 것입니다. Introduction to the Build Lifecycle - Lifecycle Reference을 참조하십시오. 나는 회색에 익숙하지 해요,하지만 여기에 예를 사용하여 부두입니다 : start
에 대한 위상이 pre-integration-test
및 stop
이 post-integration-test
인 것을
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<contextPath>/xxx</contextPath>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
참고. 그리즐리 메이븐 플러그인이 있는지 확실하지 않지만 대신 maven-antrun-plugin을 사용할 수 있습니다.
두 번째 옵션은 JUnit RunListener을 사용하는 것입니다. RunListener
그래서 당신이 RunStarted 및 RunFinished을 수신 할 수 등
public class RunListener {
public void testRunStarted(Description description) throws Exception {}
public void testRunFinished(Result result) throws Exception {}
public void testStarted(Description description) throws Exception {}
public void testFinished(Description description) throws Exception {}
public void testFailure(Failure failure) throws Exception {}
public void testAssumptionFailure(Failure failure) {}
public void testIgnored(Description description) throws Exception {}
}
테스트 시작, 테스트 종료, 테스트 실패, 시험 성공 등의 이벤트를 테스트하기 위해 수신합니다. 이것들은 당신이 원하는 서비스를 시작/중지시킬 것입니다. 그런 다음, 확실한, 당신은 사용하여 사용자 정의 리스너를 지정할 수 있습니다
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
</property>
</properties>
</configuration>
</plugin>
을이 JUnit을하지 않을 경우 사용하는 하나의 Maven Surefire Plugin, Using JUnit, Using custom listeners and reporters
에서입니까? – TheWhiteRabbit
POJO 또는 TestNG 테스트를 사용하는 경우 @BeforeClass를 사용할 수 있습니다. – TheWhiteRabbit
@TechExchange Maven surefire를 사용하고 있음을 명확히하기위한 질문 업데이트 – hertzsprung