如何在 maven 中集成 postman 集合 pom.xml

How to integrate postman collection in maven pom.xml

我有 postman.collection.json 个文件,我可以通过 newman 并使用以下命令 运行 这些集合文件。

   newman run test.postman.collection.json -e environment.collection.json -d test.csv 

它 运行 成功并正在回复。

我只想通过使用 Maven 系统获得相同的行为。我需要将它与 pom.xml 集成,以便该文件将 运行 上述集合。

这可能吗?如果可以 运行 像这样,请分享一个示例来展示如何。

有一些非官方的邮递员 运行Maven 人员,like this or this。我从来没有尝试过这些,所以我不能推荐它们中的任何一个。

我更喜欢在 integration-testverify 生命周期阶段使用 maven-exec-plugin 到 运行 postman / newman 集合。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>
                    <!-- PATH_TO_NEWMAN_EXECUTABLE-->
                </executable>
                <commandlineArgs>
                    run <!--PATH_TO_COLLECTION_JSON--> -e <!--PATH_TO_ENVIRONMENT_JSON-->
                </commandlineArgs>
            </configuration>
        </execution>
    </executions>
</plugin>

此外,您可以将可用的 newman 集成到 Maven docker 图像和 运行 作为管道。

    spec:
  containers:
  - image: "miksonx/node-newman-maven"
    imagePullPolicy: "Always"
    name: "maven"
    tty: true
"""
...
   stages {
       stage('Unit Test') {
           agent{
               kubernetes {
                   yaml NodeNewmanMaven
               }
           }
           steps {
               container(MVN_AGENT) {
                   sh 'mvn clean integration-test'
               }
           }
    }

https://miksonx.wordpress.com/2021/04/19/postman-newman-using-maven-under-jenkins-kuberenets/