【问题标题】:How to build maven artifact that run test suites? How 'sbt test' works?如何构建运行测试套件的 Maven 工件? “sbt 测试”如何工作?
【发布时间】:2017-11-09 14:17:22
【问题描述】:

我是 scala 开发人员,所以我会尝试用 sbt 示例来解释我的想法,但我相信 java 开发人员可以理解我

传统的scala/java项目结构如下:

src ->
 - main
 - test
 - it

test 文件夹在概念上用于单元测试(用于测试应用程序逻辑)。所以你可以运行'sbt test'并测试你的应用程序。此代码必须靠近您的应用程序。

可能是题外话,这是我的问题:

是否可以构建运行我所有测试的 jar 工件?我不想仅仅为了运行我的测试而启动 sbt。我想用集成测试套件构建许多 jar 工件

java my-super-service-it-case1.jar

如果测试通过,这会给我退出代码 0

java my-super-service-it-case2.jar 

等等……

我相信我需要在主块内运行测试..

【问题讨论】:

    标签: java scala unit-testing testing integration-testing


    【解决方案1】:

    我不建议您在程序的主要功能中混合您的任何测试,有一个非常好的插件可以完全满足您的需求,Maven Surefire Plugin 它应该可以在 Scala 中正常工作,但从来没有我自己搞砸了 Scala。

    在这里写出你需要的东西太多了,但它在文档和大量示例中都有很好的介绍。您可以指定包含和排除的不同目标,例如,您可以执行单元测试或验收测试,例如:

    mvn verify -P acceptance-tests -Dbuild.env=sit
    

    在POM.XML 文件中配置了以下配置文件

    <profile>
      <id>acceptance-tests</id>
      <activation>
        <property>
          <name>env.BUILD_STAGE</name>
          <value>ACCEPTANCE</value>
        </property>
      </activation>
      <build>
        <plugins>
          <!-- skip unit tests -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
    
          <!-- run acceptance tests (during integration-test phase) -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <includes>
                <include>**/*AT*.*</include>
              </includes>
              <excludes>
                <exclude>**/*Test.*</exclude>
                <exclude>**/*IT.*</exclude>
              </excludes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    

    我所有的验收测试都用 AT 命名,例如 myTestAT.java

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 2014-12-13
      • 2022-11-03
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多