PS C:\Users\86137\Desktop\UmsAdminTest> mvn test [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.acicii:UmsAdminTest >----------------------- [INFO] Building UmsAdminTest 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- allure-maven:2.14.0:report (default) @ UmsAdminTest --- [INFO] Rendering content with org.apache.maven.skins:maven-default-skin:jar:1.3 skin. [INFO] Allure installation directory C:\Users\86137\Desktop\UmsAdminTest/.allure [INFO] Try to finding out allure 2.30.0 [INFO] Generate Allure report (report) with version 2.30.0 [INFO] Generate Allure report to C:\Users\86137\Desktop\UmsAdminTest\target\site/allure-maven-plugin [ERROR] Directory C:\Users\86137\Desktop\UmsAdminTest\target\allure-results not found [WARNING] Allure report was skipped because there is no results directories found. [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ UmsAdminTest --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ UmsAdminTest --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 2 source files to C:\Users\86137\Desktop\UmsAdminTest\target\classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ UmsAdminTest --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\Users\86137\Desktop\UmsAdminTest\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ UmsAdminTest --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:\Users\86137\Desktop\UmsAdminTest\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ UmsAdminTest --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [INFO] [
时间: 2025-08-02 18:26:20 浏览: 1
<think>我们正在解决Maven测试时Allure报告目录未找到的问题,具体是`mvntest`后`allure-results`目录未生成。根据引用内容,我们可以总结以下几点:1.引用[1]:提到了Allure的properties配置,其中`allure.results.directory`指定了结果目录(默认为`target/allure-results`),`allure.report.directory`指定了报告目录。2.引用[2]:提到了Maven项目中的编码问题,但同时也展示了在pom.xml中设置编码为UTF-8。3.引用[3]:用户遇到目标文件夹下未生成`allure-results`目录的问题,并展示了一个pom.xml的片段。4.引用[4]:展示了JUnit5与Gradle集成Allure时,生成空`allure-result`目录的问题,其中提到了Allure插件的配置。因此,我们需要检查以下几个方面:-确保Allure的Maven插件正确配置,并且指定了结果目录(如果没有指定,则默认为`target/allure-results`)。-确保测试执行正确,因为只有测试执行后才会生成结果目录。-检查Maven项目的构建配置,确保源文件编码设置正确(避免因乱码导致的问题)。解决方案步骤:1.**检查AllureMaven插件的配置**:在pom.xml中,确保已经添加了Allure的Maven插件,并且配置了正确的版本。同时,可以通过属性配置来指定结果目录。例如,在pom.xml的`<properties>`部分添加:```xml<properties><allure.results.directory>target/allure-results</allure.results.directory><!--其他属性--></properties>```同时,确保插件配置正确:```xml<build><plugins><plugin><groupId>io.qameta.allure</groupId><artifactId>allure-maven</artifactId><version>2.10.0</version><!--使用最新版本--><configuration><reportVersion>2.14.0</reportVersion><!--指定Allure报告版本--></configuration></plugin></plugins></build>```2.**确保测试执行**:运行`mvntest`命令时,确保测试用例被正确执行。如果测试用例没有被执行(例如,测试类命名不符合约定,或者测试被跳过),则不会生成结果目录。可以检查Maven的输出日志,确认测试是否执行。3.**检查测试框架的适配器(adapter)**:Allure需要与测试框架(如JUnit、TestNG)的适配器才能收集测试结果。确保在pom.xml中包含了对应的适配器依赖。例如,对于JUnit5,可以添加:```xml<dependencies><dependency><groupId>io.qameta.allure</groupId><artifactId>allure-junit5</artifactId><version>2.14.0</version><!--与Allure版本匹配--><scope>test</scope></dependency></dependencies>```4.**检查编码问题**:虽然引用[2]提到的是乱码问题,但这里也可能会导致其他问题。确保项目构建的编码设置为UTF-8:```xml<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties>```5.**运行命令**:运行`mvntest`后,检查项目目录下的`target`文件夹,看是否生成了`allure-results`目录。如果没有,可以尝试运行`mvnallure:report`,这个命令有时会触发测试的执行(如果还没有执行的话)并生成报告,但注意它依赖于测试执行生成的结果。6.**如果以上步骤仍然不行**:可以尝试手动创建目录。有时候目录不存在可能是因为没有写入权限,或者路径错误。7.**参考引用[4]中的配置**:虽然引用[4]是Gradle的配置,但我们可以借鉴其版本配置。确保Allure插件和适配器的版本兼容。8.**清理后再构建**:尝试运行`mvncleantest`,清除之前的构建结果再重新测试。根据上述步骤,通常可以解决`allure-results`目录未生成的问题。注意:以上步骤中,插件版本和适配器版本需要根据实际情况选择兼容的版本。可以查看Allure官方文档获取最新版本和兼容性信息。如果问题仍然存在,请检查测试代码中是否使用了Allure的注解(如`@Description`,`@Step`等),因为如果没有使用这些注解,Allure可能不会收集信息,但至少应该生成基本的结果文件(如测试用例的执行结果)。最后,生成报告的命令是`mvnallure:report`,它会读取`allure-results`目录并生成报告到`target/allure-report`目录(默认)。相关问题:1.如何配置Allure以使用不同的结果目录?2.如何解决Allure报告中的中文乱码问题?3.如何将Allure集成到持续集成(CI)系统中?4.如何为Allure测试报告添加自定义信息?</think>### Maven测试时Allure报告目录未找到的解决方案
当执行`mvn test`后未生成`allure-results`目录时,通常由以下原因导致。请按顺序排查:
#### 1. **检查Allure插件配置**
在`pom.xml`中需显式配置结果目录路径:
```xml
<properties>
<allure.results.directory>target/allure-results</allure.results.directory> <!-- 关键配置 -->
</properties>
```
若未指定,Allure可能使用临时路径导致目录不可见[^1][^3]。
#### 2. **验证测试框架适配器**
确保添加测试框架适配器依赖(以JUnit 5为例):
```xml
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId> <!-- 必须的适配器 -->
<version>2.24.0</version> <!-- 与Allure版本匹配 -->
<scope>test</scope>
</dependency>
```
缺少适配器会导致测试结果无法写入目录[^4]。
#### 3. **检查构建插件配置**
在`pom.xml`的`<build>`中配置Allure插件:
```xml
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.10.0</version> <!-- 推荐最新版本 -->
<configuration>
<reportVersion>2.24.0</reportVersion>
</configuration>
</plugin>
```
版本不匹配会导致功能异常[^4]。
#### 4. **确认测试执行状态**
运行命令后检查Maven日志:
```bash
mvn clean test -X | grep "allure-results" # 查看路径生成日志
```
若测试被跳过(如`mvn clean`后未执行`test`),则不会生成目录。
#### 5. **解决编码问题(防乱码)**
在`pom.xml`中设置全局编码:
```xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 防止乱码 -->
</properties>
```
乱码可能导致文件写入失败[^2]。
#### 6. **手动创建目录(备选方案)**
在项目根目录执行:
```bash
mkdir -p target/allure-results # 手动创建目录
chmod 777 target/allure-results # 赋予写入权限
```
再运行`mvn test`,观察是否写入文件。
#### 7. **验证环境变量**
检查环境变量是否覆盖配置:
```bash
echo $ALLURE_RESULTS_DIRECTORY # 应为空或与pom一致
```
环境变量优先级高于`pom.xml`[^1]。
> **总结流程**:配置适配器 → 设置结果目录 → 检查编码 → 执行测试 → 验证日志。完成上述步骤后,`target/allure-results`目录应正常生成。
阅读全文
相关推荐








