Nam*_*man 11 java xml testng maven allure
我们有一个基于maven框架的测试套件,由多模块组成.使用的模块 -
project [没有代码]test[ @Test类包含在/ src/main/java下,testng.xml在/ src/main/resources中 ]core [配置为执行环境设置的基本实用程序]driver [配置测试存储区并使用testng调制报告生成]尝试使用诱惑整合报告生成,我在项目中 添加了以下内容pom.xml-
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
</argLine>
<properties>
<property>
<name>listener</name>
<value>ru.yandex.qatools.allure.junit.AllureRunListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.10.v20150310</version>
<configuration>
<webAppSourceDirectory>${project.build.directory}/site/allure-maven-plugin</webAppSourceDirectory>
<stopKey>stop</stopKey>
<stopPort>1234</stopPort>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)
同样对测试 的依赖关系pom.xml-
<!--allure related dependencies-->
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-testng-adaptor</artifactId>
<version>1.4.16</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.detro.ghostdriver</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-java-annotations</artifactId>
<version>1.5.0.RC2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
步骤1 - 执行测试后,
mvn exec:java -pl driver我可以看到生成的/target/allure-results文件夹.第2步 -
mvn jetty:run读取Started Jetty Server第3步 - 但是当我在浏览器上访问localhost:8080时,它只有一个标题
目录 :/
题
我怀疑我指定的路径在某处是不正确的,所以码头无法找到报告,但无法弄清楚在哪里.是针对执行的测试还是针对testng.xml资源的测试?或者我只需要纠正pom中某处的路径?
我试图使用依赖项(在父projectpom中)正确的方式也是?
更新1
使用的exec配置如下 -
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<mainClass>com.driver.Driver</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
感谢任何回应.
这个问题有很多开放点,由于缺乏细节而不清楚。
根据您的描述,项目结构如下:
project
|
|--- test-module
|--- core-module
|--- driver-module (depends on `core` and `test`)
|
\ pom.xml
Run Code Online (Sandbox Code Playgroud)
driver实际上,您仅通过模块和通过执行测试exec-maven-plugin,但是allure文档指定了经典方法来执行该test阶段,即专用于测试执行的 Maven 阶段(通过maven-surefire-plugin,在此阶段由 Maven 通过默认绑定自动调用))。
maven-surefire-plugin您实际上按照其文档的指定进行配置:pom.xml在这种情况下,将其指定到父文件中就可以了,在其部分 > Maven 将在执行默认绑定pluginManagement期间获取其全局配置。default-testmaven-surefire-plugin
然而,整个机制与阶段相关test。你执行吗?
您没有提供有关exec-maven-plugin该模块的详细信息以及它应该对driver模块执行什么操作以及为什么您将使用该jetty-maven-plugin来查看报告。通常情况下,测试报告是可用的,并且可以直接看到html文件,不需要将它们托管在嵌入式jetty服务器中,除非整个流程需要(CI、部署到公司服务器等)。这些报告还应该提供给项目文档站点,可以通过site生命周期及其maven-site-plugin.
根据您的详细信息,您共享jetty-maven-plugin指向site文件夹的配置:该文件夹是否在此test阶段生成(如果您调用它)?或者在你exec调用期间?
关于您在父pom中使用依赖项的方式,您实际上没有在问题中共享它,所以不容易提供帮助。通常,您会将依赖项放在dependencies所有模块共用的父 pom 部分中(例如log4j,经典示例是每个模块都会使用的东西)。否则,您将使用dependencyManagement父 pom 的部分来管理可由一个或多个模块使用的某些依赖项的版本(但模块需要重新声明它们才能有效使用它们,但忽略它们的版本,由父级指定) )。也就是说,父 pom 是治理和协调的中心位置。
更新
关于/target/allure-results生成的文件夹,您还需要检查其内容是否为有效的站点目录(即,例如它应包含index.html)。
创建一个新的 Maven webapp 项目并将以下内容添加到其pom.xml文件中:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.10.v20150310</version>
<configuration>
<webAppSourceDirectory>${project.build.directory}/site</webAppSourceDirectory>
<stopKey>stop</stopKey>
<stopPort>1234</stopPort>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
(注意:完全按照您的问题,但仅指向目录site)
并执行:
mvn clean install site
mvn jetty:run
Run Code Online (Sandbox Code Playgroud)
Maven 站点(在site上面调用的阶段生成)将在(默认 jetty URL)可用localhost:8080。那是因为 anindex.html被生成了。
但是,如果我手动删除index.html,码头将显示一个Directory: /页面,列出可用的文件。
因此,魅力报告很可能没有生成文件index.html,因为很可能它并不打算生成文件,而只是在此test阶段生成的 HTML 报告。
| 归档时间: |
|
| 查看次数: |
1353 次 |
| 最近记录: |