尝试运行 Jmeter 测试时 Maven 中出现未知生命周期错误

问题描述 投票:0回答:1

您好,我一直在尝试在 Maven 中运行我的 jmeter 脚本,尽管我的 POM.xml 文件似乎是正确的,但我不断收到此未知的生命周期错误。

有人可以帮助我并让我知道我做错了什么吗?我正在运行下面列出的 MV 命令,该命令引用了我在 POM.xml 中定义的属性。当我直接在 Jmeter 中运行 jmx 文件时,它运行良好。但是当我尝试在本地 Maven 中运行它时,我遇到了这个错误。

MVN命令:

mvn clean verify -e -Dtest.testcasename=Security4 -Dtest.environment=AllTests -Dtest.product=AllAPIs

MVN 错误消息:

INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.489 s
[INFO] Finished at: 2023-10-19T12:15:32-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase ".testcasename=Security4". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
org.apache.maven.lifecycle.LifecyclePhaseNotFoundException: Unknown lifecycle phase ".testcasename=Security4". You must specify a valid lifecycle phase or a goal 

POM.xml 文件:

    <?xml version="1.0" encoding="UTF-8"?>

<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>com.mycompany.app</groupId>

    <artifactId>Service</artifactId>

    <packaging>jar</packaging>

    <version>1.0-SNAPSHOT</version>

    <name>DPHTest</name>

    <description>This application contains the Jmeter Service Tests for my app.</description>

 

    <properties>

        <Environment>${test.environment}</Environment>

        <!--<Region>${test.region}</Region>-->

        <Server>${test.server}</Server>

        <Product>${test.product}</Product>

        <TestCaseName>${test.testcasename}</TestCaseName>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <maven.compiler.source>1.8</maven.compiler.source>

        <maven.compiler.target>1.8</maven.compiler.target>

    </properties>

 

    <dependencies>

        <!-- https://mvnrepository.com/artifact/junit/junit -->

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

            <version>4.13.1</version>

            <scope>test</scope>

        </dependency>

    </dependencies>

 

    <build>

        <plugins>

            <plugin>

                <groupId>com.lazerycode.jmeter</groupId>

                <artifactId>jmeter-maven-plugin</artifactId>

                <version>3.5.0</version>

                <executions>

                    <!-- Generate JMeter configuration -->

                    <execution>

                        <id>configuration</id>

                        <goals>

                            <goal>configure</goal>

                        </goals>

                    </execution>    

                    <!-- Run JMeter tests -->

                    <execution>

                        <id>jmeter-tests</id>

                        <goals>

                            <goal>jmeter</goal>

                        </goals>

                    </execution>

                    <!-- Fail build on errors in test -->

                    <execution>

                        <id>jmeter-check-results</id>

                        <goals>

                            <goal>results</goal>

                        </goals>

                    </execution>

                </executions>

                <configuration>

                    <jmeterVersion>5.4.3</jmeterVersion>

                    <testPlanLibraries>

                        <artifact>org.apache.logging.log4j:log4j-core:2.17.0</artifact>

                    </testPlanLibraries>

                    <failBuildIfResultFileIsEmpty>false</failBuildIfResultFileIsEmpty>

                    <testFilesIncluded>

                        <!-- <jMeterTestFile>Security4.jmx</jMeterTestFile>   -->

                        <jMeterTestFile>${testcasename}.jmx</jMeterTestFile>

                    </testFilesIncluded>

                    <ignoreResultFailures>false</ignoreResultFailures>

                    <appendResultsTimestamp>true</appendResultsTimestamp>

                    <resultsFileFormat>csv</resultsFileFormat>

                    <generateReports>true</generateReports>

                    <reportConfig>

                    </reportConfig>

                    <!-- change protocol, server and port of tested API/web Application  -->

                    <propertiesUser>

                        <csvSource>${basedir}/src/test/resources</csvSource>

                        <!--<Server>${server}</Server>-->

                        <zap.host>${zap.server}</zap.host>

                        <environment>${Environment}</environment>

                        <!-- <region>${Region}</region> -->

                        <product>${Product}</product>

                        <!--<testcasename>${TestCaseName}</testcasename>-->

                        <targetResults>${basedir}/target/jmeter/results</targetResults>

                        <!--  <Port>${port}</Port> -->

                        <zap.port>${zap.port}</zap.port>

                    </propertiesUser>

                    <propertiesJMeter>

                        <log_level.jmeter>DEBUG</log_level.jmeter>

                        <jmeter.save.saveservice.response_data>true</jmeter.save.saveservice.response_data>

                        <jmeter.save.saveservice.url>true</jmeter.save.saveservice.url>

                    </propertiesJMeter>

                </configuration>    

               

            </plugin>

        </plugins>

    </build>

</project>
maven jmeter maven-plugin jmeter-plugins jmeter-maven-plugin
1个回答
0
投票
  1. 请参阅您的 shell 文档,看起来您的 shell 不允许在参数名称中使用点,这些点需要 转义或用引号括起来

  2. 还可以考虑将您的JMeter Maven Plugin版本升级到最新版本,目前为3.8.0,它将下载最新的JMeter,并且根据JMeter最佳实践,您应该始终使用最新版本的JMeter .

  3. 我不认为 JMeter Maven 插件尊重 dependency 块,你应该使用 特殊语法来操作 JMeter Classpath

更多信息:如何使用 JMeter Maven 插件

© www.soinside.com 2019 - 2024. All rights reserved.