2017-03-02 61 views
0

我就與的Arquillian和TestNG一個簡單的測試和Maven與IT無故障測試時拋出異常的Arquillian TestNG的行家

@Test(enabled=true) 
@OperateOnDeployment("test") 
public void testError() throws Exception { 
    throw new Exception(); 
} 

在理論測試將是錯誤的和下面的測試將不會被執行,但沒有追加,所有測試結果都OK,所以我不能真正測試我的功能,因爲即使引發異常也沒有錯誤追加。這是不正常的。

我重新建立一個簡單的web應用具有以下的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>sample.spnego</groupId> 
<artifactId>sample-app</artifactId> 
<packaging>war</packaging> 
<version>1.0</version> 
<name>sample-app</name> 

<dependencyManagement> 
    <dependencies> 
     <!-- Define the version of JBoss' Java EE 6 APIs we want to import. Any 
      dependencies from org.jboss.spec will have their version defined by this 
      BOM --> 
     <dependency> 
      <groupId>org.jboss.spec</groupId> 
      <artifactId>jboss-javaee-6.0</artifactId> 
      <version>3.0.3.Final</version> 
      <scope>import</scope> 
      <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>org.jboss.arquillian</groupId> 
      <artifactId>arquillian-bom</artifactId> 
      <!-- <version>1.1.8.Final</version> --> 
      <version>1.1.12.Final</version> 
      <scope>import</scope> 
      <type>pom</type> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 




<dependencies> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.spec</groupId> 
     <artifactId>jboss-javaee-6.0</artifactId> 
     <version>1.0.0.Final</version> 
     <type>pom</type> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.enterprise</groupId> 
     <artifactId>cdi-api</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.spec.javax.annotation</groupId> 
     <artifactId>jboss-annotations-api_1.1_spec</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.spec.javax.ejb</groupId> 
     <artifactId>jboss-ejb-api_3.1_spec</artifactId> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.arquillian.testng</groupId> 
     <artifactId>arquillian-testng-container</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.arquillian.protocol</groupId> 
     <artifactId>arquillian-protocol-servlet</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.eu.ingwar.tools</groupId> 
     <artifactId>arquillian-suite-extension</artifactId> 
     <version>1.1.2</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.6.4</version> 
     <scope>provided</scope> 
    </dependency> 


    <dependency> 
     <groupId>org.apache.nutch</groupId> 
     <artifactId>nutch</artifactId> 
     <version>2.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.wildfly.arquillian</groupId> 
     <artifactId>wildfly-arquillian-container-managed</artifactId> 
     <version>2.0.2.Final</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 



<profiles> 
    <profile> 
     <id>integration</id> 
     <build> 
      <plugins> 
       <!-- <plugin> --> 
       <!-- <groupId>org.apache.maven.plugins</groupId> --> 
       <!-- <artifactId>maven-surefire-plugin</artifactId> --> 
       <!-- <version>2.19.1</version> --> 
       <!-- </plugin> --> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-failsafe-plugin</artifactId> 
        <version>2.19.1</version> 

        <configuration> 
         <systemPropertyVariables> 
          <jboss.server.log.dir>C:/dev/servers/wildfly-9.0.2.Final/standalone/log</jboss.server.log.dir> 
          <arquillian.launch>jbossas-managed</arquillian.launch> 
          <jbossas.startup.timeout>240</jbossas.startup.timeout> 

         </systemPropertyVariables> 
         <includes> 
          <include>*.java</include> 
         </includes> 
         <!-- <groups>org.jboss.arquillian.testng.Arquillian</groups> --> 
        </configuration> 
        <executions> 
         <execution> 
          <goals> 
           <goal>integration-test</goal> 
           <goal>verify</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 

    </profile> 
</profiles> 

然後以下ArquillianDeploymentHelper:

@ArquillianSuiteDeployment 
public class ArquillianDeploymentHelper { 

//private static final Logger LOGGER = Logger.getLogger(ArquillianDeploymentHelper.class); 

private static String WEBAPP_SRC = "src/main/webapp"; 
private static String POM_FILE = "pom.xml"; 
private static String ARCHIVE_NAME = "test.war"; 

@Deployment(name = "test") 
public static Archive<?> generateDefaultDeployment() { 

    // Generate the default WAR used by all *IT tests using @OperateOnDeployment("AofWeb") annotation 
    //LOGGER.info("Generating " + ARCHIVE_NAME + " archive ..."); 

    PomEquippedResolveStage pom = Maven.resolver().loadPomFromFile(POM_FILE); 
    ScopeType[] scopes = {ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.TEST}; // no SYSTEM and no PROVIDED 
    File[] libs = pom.importDependencies(scopes).resolve().using(TransitiveStrategy.INSTANCE).asFile(); 

    WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME) 

      .addAsWebInfResource(new File(WEBAPP_SRC, "WEB-INF/beans.xml")); 
    archive.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class) 
      .importDirectory(WEBAPP_SRC).as(GenericArchive.class), 
      "/", Filters.include(".*\\.(?i)(jpg|js|png|gif|bmp|html|xhtml|css)$")); 

    // No need to log the content anymore, the archive is kept in target directory 
    // "deploymentExportPath" variable in arquillian.xml 
// LOGGER.info(archive.toString(true)); 

    return archive; 
} 

}

和arquillian.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<arquillian xmlns="http://jboss.org/schema/arquillian" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://jboss.org/schema/arquillian  http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> 

<!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature --> 
<defaultProtocol type="Servlet 3.0" /> 

<!-- Keep generated archive for inspection 
--> 
<engine> 
     <property name="deploymentExportPath">target/</property> 
</engine> 



<!-- Local JBoss/WildFly instance --> 
<container qualifier="jbossas-managed" default="true"> 
    <configuration> 
     <property name="jbossHome">${env.JBOSS_HOME}</property> 
     <property name="serverConfig">standalone-real-continuous-integration.xml</property> 
     <!-- true : server must be started by the user, false : arquillian will start it itself --> 
     <property name="allowConnectingToRunningServer">true</property> 
    </configuration> 
</container> 

<!-- Remote JBoss/WildFly instance --> 
<container qualifier="jbossas-remote" default="false"> 
    <configuration> 
     <property name="managementAddress">remoteHost</property> 
     <property name="managementPort">9999</property> 
    </configuration> 
</container> 

wildfly 9.0.2版

注:我測試的Arquillian教程是BOM和測試罐中,而不是戰爭和異常產生測試失敗的相同版本=> OK

以上配置:異常不會產生failut => NOK

任何想法?

編輯:

 <dependency> 
     <groupId>org.wildfly.arquillian</groupId> 
     <artifactId>wildfly-arquillian-container-managed</artifactId> 
      <version>2.1.0.Alpha1</version> 
     <scope>test</scope> 
    </dependency> 

,並使用Arquillian.xml

,而不是:我將在測試工作重現問題

<dependency> 
<groupId>org.jboss.arquillian.container</groupId> 
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId> 
<version>1.0.0.CR9</version> 
<scope>test</scope> 
</dependency> 
<dependency> 
<groupId>org.jboss.weld</groupId> 
<artifactId>weld-core</artifactId> 
<version>2.3.5.Final</version> 
<scope>test</scope> 
</dependency> 
+1

我使用類似的配置進行測試,並且在引發異常時我的測試失敗。順便說一句,「測試是OK」,這是否意味着成功或只是跳過?你能提供輸出嗎? – Adonis

+1

你是通過maven-surefire-plugin還是通過maven-failsafe-plugin運行你的IT? – khmarbaise

+0

也很高興知道您的依賴關係的版本。 –

回答

1

最後它似乎是最後tesNG版本6.10如果我降級到6.9.10它正在工作!

+0

謝謝,有同樣的問題,通過降級TestNG版本來解決它:) –

0

也許這將幫助你:https://stackoverflow.com/a/32066322/4471199

萬無一失,Maven的插件不承認與* IT結束測試。 您應該將其名稱更改爲*測試或使用其他技術

+0

對我來說不是問題,因爲我之前說過它是測試NG的最後一個版本,當它降級版本工作時,我不知道是誰投票給你,但示例顯示它正在工作,只有結果不好...此外,在我使用maven-failsafe-plugin的例子中,我不知道你爲什麼在談論surefire ... – cyril