为什么MVN CLAIN验证仅运行SureFire插件

发布于 2025-02-10 01:56:47 字数 9121 浏览 1 评论 0原文

我的项目结构是:

Project_Name

|-src/main/java

|-src/test/java

    |-default package

        |-MyIT.java

    |-steps

        |-MySteps.java

|-pom.xml

myit.java:

@RunWith(SerenityRunner.class)
public class MyIT {
    
    @Steps
    MySteps mySteps;
    
    
    @BeforeClass
    public static void setUp() {
    RestAssured.baseURI="https://restcountries.com/";
    System.out.println("1");
    }
    
    
    @Test
    @Title("Check \"Republic Of India\"")
    public void verify_that_given_string_found_in_the_response() {
    
    
        
          mySteps.whenIOpenURLForIndia(); 
          mySteps.thenRepublicOfIndiaFoundInResponse();
    }
}

mysteps.java:

public class MySteps {

    
    @Step("When I Open the URL for India")
    public void whenIOpenURLForIndia() {
        SerenityRest.given().relaxedHTTPSValidation().basePath("v2/name/{country}").pathParam("country", "INDIA").when().get();
    }
    
    @Step("Then \"Republic of India\" found in the response")
    public void thenRepublicOfIndiaFoundInResponse() {
        
        SerenityRest.lastResponse().then().body("[1].altSpellings",hasItem("Republic of India"));
    }
}

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>org.restcountries</groupId>
  <artifactId>Serenity_RestAssured_Assignment1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <name>Serenity_RestAssured_Assignment1</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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


     <dependencies>
            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-core</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-junit</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-rest-assured -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-rest-assured</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                
            </dependency>

            <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>4.4.0</version>
                
            </dependency>
            
            <!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>java-hamcrest</artifactId>
                <version>2.0.0.0</version>
                
            </dependency>
            
            

  </dependencies>

 <build>
    
    <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.8.1</version>
                            <configuration>
                                <source>1.8</source>
                                <target>1.8</target>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M4</version>
                            <configuration>
                                <skip>true</skip>
                                
                            </configuration>
                        </plugin>
                        <plugin>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>3.0.0-M4</version>
                            <configuration>
                                <skipTests>false</skipTests>
                            </configuration>
                            <executions>
                                <execution>

                                    <goals>
                                        <goal>integration-test</goal>
                                        <goal>verify</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>

                    </plugins>
                    
    </pluginManagement>
  </build>
  



</project>

现在使用它运行时:

mvn clean verify 

其输出是:

    [INFO] Scanning for projects...
    [INFO]
    [INFO] ---------< org.restcountries:Serenity_RestAssured_Assignment1 >---------
    [INFO] Building Serenity_RestAssured_Assignment1 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Deleting C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory 
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\main\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 2 source files to 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Tests are skipped.
    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Serenity_RestAssured_Assignment1 ---
    [WARNING] JAR will be empty - no content was marked for inclusion!
    [INFO] Building jar: 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\Serenity_RestAssured_Assignment1-0.0.1-SNAPSHOT.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.305 s
    [INFO] Finished at: 2022-06-24T04:14:55+05:30

它显示“跳过测试”,“ jar将为空”。

我的问题是为什么MVN验证尽管命名约定适合集成测试(Maven Failsafe插件),但仍未运行 myit.java 测试。 Maven SureFire插件正在跳过测试,但是Maven FailSafe插件应标识Myit.java测试。

编辑:MVN清洁测试 - 编译失败:Integration-Test能够成功运行myit.java测试,但mvn Clean Clean test-Compile Failsafe:verify not over not。

My project structure is:

Project_Name

|-src/main/java

|-src/test/java

    |-default package

        |-MyIT.java

    |-steps

        |-MySteps.java

|-pom.xml

MyIT.java:

@RunWith(SerenityRunner.class)
public class MyIT {
    
    @Steps
    MySteps mySteps;
    
    
    @BeforeClass
    public static void setUp() {
    RestAssured.baseURI="https://restcountries.com/";
    System.out.println("1");
    }
    
    
    @Test
    @Title("Check \"Republic Of India\"")
    public void verify_that_given_string_found_in_the_response() {
    
    
        
          mySteps.whenIOpenURLForIndia(); 
          mySteps.thenRepublicOfIndiaFoundInResponse();
    }
}

MySteps.java:

public class MySteps {

    
    @Step("When I Open the URL for India")
    public void whenIOpenURLForIndia() {
        SerenityRest.given().relaxedHTTPSValidation().basePath("v2/name/{country}").pathParam("country", "INDIA").when().get();
    }
    
    @Step("Then \"Republic of India\" found in the response")
    public void thenRepublicOfIndiaFoundInResponse() {
        
        SerenityRest.lastResponse().then().body("[1].altSpellings",hasItem("Republic of India"));
    }
}

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>org.restcountries</groupId>
  <artifactId>Serenity_RestAssured_Assignment1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <name>Serenity_RestAssured_Assignment1</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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


     <dependencies>
            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-core</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-junit</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-rest-assured -->
            <dependency>
                <groupId>net.serenity-bdd</groupId>
                <artifactId>serenity-rest-assured</artifactId>
                <version>3.1.15</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                
            </dependency>

            <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>4.4.0</version>
                
            </dependency>
            
            <!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
            <dependency>
                <groupId>org.hamcrest</groupId>
                <artifactId>java-hamcrest</artifactId>
                <version>2.0.0.0</version>
                
            </dependency>
            
            

  </dependencies>

 <build>
    
    <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.8.1</version>
                            <configuration>
                                <source>1.8</source>
                                <target>1.8</target>
                            </configuration>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M4</version>
                            <configuration>
                                <skip>true</skip>
                                
                            </configuration>
                        </plugin>
                        <plugin>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>3.0.0-M4</version>
                            <configuration>
                                <skipTests>false</skipTests>
                            </configuration>
                            <executions>
                                <execution>

                                    <goals>
                                        <goal>integration-test</goal>
                                        <goal>verify</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>

                    </plugins>
                    
    </pluginManagement>
  </build>
  



</project>

Now when I run it using:

mvn clean verify 

its output is:

    [INFO] Scanning for projects...
    [INFO]
    [INFO] ---------< org.restcountries:Serenity_RestAssured_Assignment1 >---------
    [INFO] Building Serenity_RestAssured_Assignment1 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Deleting C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory 
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\main\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\test\resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 2 source files to 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\test-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ Serenity_RestAssured_Assignment1 ---
    [INFO] Tests are skipped.
    [INFO]
    [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ Serenity_RestAssured_Assignment1 ---
    [WARNING] JAR will be empty - no content was marked for inclusion!
    [INFO] Building jar: 
    C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\Serenity_RestAssured_Assignment1-0.0.1-SNAPSHOT.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.305 s
    [INFO] Finished at: 2022-06-24T04:14:55+05:30

It shows “tests are skipped” and “jar will be empty”.

My question is why mvn verify is not running MyIT.java test despite that naming convention is proper for integration test(maven failsafe plugin). Maven surefire plugin is skipping the tests but maven failsafe plugin should identify the MyIT.java test.

EDIT: mvn clean test-compile failsafe:integration-test is able to run the MyIT.java test successfully but mvn clean test-compile failsafe:verify does not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2025-02-17 01:56:47

问题仅仅是因为您已经定义了 nofollow noreferrer“> maven-failsafe-plailsafe-plagin-plugin 仅在插件管理中。

通常的方法是定义插件管理中的版本,而绑定必须在构建区域中进行。

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>3.0.0-M7</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

我还建议升级您的二手插件,这意味着在插件管理中定义所有使用的插件的新版本。

此外,您不应为Maven-Surefire-Plugin定义配置:

<configuration>
  <skip>true</skip>
</configuration>

The issue is simply because you have defined the maven-failsafe-plugin in pluginManagement only.

The usual way is to define the version in pluginManagement while the binding has to be done in build area.

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>3.0.0-M7</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

I also recommend to upgrade your used plugins which means define newer versions of all used plugin in pluginManagement.

Furthermore you should not define a configuration for maven-surefire-plugin:

<configuration>
  <skip>true</skip>
</configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文