2014-05-04 49 views
0

整合pom.xml看起來像Maven的貨物:集成測試運行之前貨物部署戰爭

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <version>2.12</version> 
      <executions> 
       <execution> 
        <phase>integration-test</phase> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <version>1.4.8</version> 
      <configuration> 
       <container> 
        <containerId>tomcat7x</containerId> 
        <zipUrlInstaller> 
         <url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip</url> 
         <downloadDir>${project.build.directory}/downloads</downloadDir> 
         <extractDir>${project.build.directory}/extracts</extractDir> 
        </zipUrlInstaller> 
       </container> 
       <configuration> 
        <properties> 
         <cargo.servlet.port>9090</cargo.servlet.port> 
        </properties> 
       </configuration> 
       <deployables> 
        <deployable> 
         <groupId>com.yahoo.pryme_services.inventory</groupId> 
         <artifactId>services</artifactId> 
         <type>war</type> 
         <pingURL>http://localhost:9090/services/rest/hello</pingURL> 
        </deployable> 
       </deployables> 
      </configuration> 
      <executions> 
       <execution> 
        <id>start-container</id> 
        <goals> 
         <goal>start</goal> 
        </goals> 
        <phase>pre-integration-test</phase> 
       </execution> 
       <execution> 
        <id>stop-container</id> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
        <phase>post-integration-test</phase> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

測試看起來像

public class TestHelloIT { 
    @Test 
    public void testHello() { 
     final String url = "http://localhost:9090/services/rest"; 
     final Client client = ClientBuilder.newClient(); 
     final WebTarget target = client.target(url).path("hello"); 
     final Invocation.Builder builder = target.request(); 
     final Response response = builder.get(); 

     assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); 
    } 
} 

當我運行mvn clean install,我看到測試運行和故障及貨物沒有日誌說它正在部署。

[INFO] Scanning for projects... 
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Pryme REST Services Integration Test 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ integration --- 
[INFO] Deleting /Users/harith/IdeaProjects/pryme_services/inventory/integration/target 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ integration --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ integration --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ integration --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory /Users/harith/IdeaProjects/pryme_services/inventory/integration/src/test/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ integration --- 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 1 source file to /Users/harith/IdeaProjects/pryme_services/inventory/integration/target/test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ integration --- 
[INFO] Surefire report directory: /Users/harith/IdeaProjects/pryme_services/inventory/integration/target/surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.yahoo.pryme_services.inventory.integration.TestHelloIT 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.469 sec <<< FAILURE! 
testHello(com.yahoo.pryme_services.inventory.integration.TestHelloIT) Time elapsed: 0.435 sec <<< ERROR! 
javax.ws.rs.ProcessingException: java.net.ConnectException: Connection refused 
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229) 
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:224) 
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655) 
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228) 
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424) 
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652) 
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:387) 
    at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:291) 
    at com.yahoo.pryme_services.inventory.integration.TestHelloIT.testHello(TestHelloIT.java:20) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) 
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) 
Caused by: java.net.ConnectException: Connection refused 
    at java.net.PlainSocketImpl.socketConnect(Native Method) 
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) 
    at java.net.Socket.connect(Socket.java:579) 
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175) 
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) 
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) 
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211) 
    at sun.net.www.http.HttpClient.New(HttpClient.java:308) 
    at sun.net.www.http.HttpClient.New(HttpClient.java:326) 
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932) 
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300) 
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) 
    at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:321) 
    at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:227) 
    ... 40 more 


Results : 

問題

我怎樣才能確保貨物部署測試戰前實際運行

回答

2

所以,事實證明,你的問題是與你的測試的名稱。重命名它HelloITTestHelloIT它應該工作。

要理解爲什麼是這樣的話,讓我們提醒Maven的生命週期中的自己:

validate 
compile 
test 
package 
integration-test 
verify 
install 
deploy 

,你會發現,你的測試運行,並在神火插件失敗。 Surefire插件在測試階段運行,也就是說,它在應用程序甚至打包之前運行,更不用說在集成測試階段將其部署到容器中。

實際上,您已經爲Failsafe插件正確命名了您的測試,該插件是您希望在整合測試階段運行的插件。默認情況下,它會提取名爲**/IT*.java,**/*IT.java**/*ITCase.java的類。

但是,Surefire插件的命名約定是**/Test*.java,**/*Test.java**/*TestCase.java。所以你設法做的是命名測試,以便它們被兩個插件拾取,並且由於Surefire先運行並且首先失敗,但它甚至沒有達到你的容器將被部署的程度。

其餘的看起來很好,所以應該工作。

+0

感謝@mardoz,好像它沒有在測試階段運行它,我可以看到正在部署的tomcat。但現在在部署了tomcat之後,我看不到任何'HelloIT.java'正在運行。我還錯過了什麼? – user3600328

+0

你能用新的輸出更新嗎? – Mardoz

相關問題