Code Monkey home page Code Monkey logo

java-testing-ecosystem's Introduction

Java Testing Ecosystem

Java 17 example workflow Quality Gate Status Coverage Lines of Code Bugs All Contributors

这个项目包含Java生态系统中各种测试框架和库的演示代码,其中的重点在于单元测试框架、Mock框架、断言库、BDD、Selenium。除了这些之外,其中的模块还涵盖了大量的测试工具库。

项目博客tu-yucheng.github.io

多版本JDK构建

就目前而言,大多数模块都是基于JDK 17(JAVA_HOME)才能正确构建和运行。此外,还有一些模块基于JDK 8/19,我们通过Maven工具链来保证这些模块能够使用单独的JDK构建。

首先,你需要同时下载这些版本的JDK。然后配置Maven工具链,在你用户目录下的.m2文件夹中创建一个toolchains.xml文件:

在该文件中添加以下内容(务必将每个工具链的<jdkHome>指向你本地该JDK版本的位置):

<?xml version="1.0" encoding="UTF-8"?>
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>17</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>D:\\xxx\\jdk-17.0.5</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>8</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>D:\\xxx\\jdk-8</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>19</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>D:\\xxx\\jdk-19.0.1</jdkHome>
        </configuration>
    </toolchain>
</toolchains>

Maven Profile

我们使用Maven profile来隔离各种测试(单元测试、集成测试、实时测试...)的执行,不同类型的测试类名必须以指定后缀结尾:

Profile 启用的测试类型
unit *UnitTest
integration *IntegrationTest
all *IntegrationTest、*UnitTest
live *LiveTest
parents None

实时(live)测试是指需要与外部系统进行交互的测试,例如数据库、消息代理、文件系统等

构建项目

不需要经常一次构建整个仓库,因为我们通常关注特定的模块。

但是,如果我们想在仅启用单元测试的情况下构建整个仓库,我们可以从仓库的根目录调用以下命令:

mvn clean install -Punit

或者,如果我们想在启用集成测试的情况下构建整个仓库,我们可以执行以下操作:

mvn clean install -Pintegration

构建单个模块

要构建特定模块,请在模块目录中运行命令:mvn clean install

你的模块可能是父模块的一部分,例如parent-boot-3parent-spring-5等,然后你需要先构建父模块,这样才能构建你的模块。我们创建了一个parents profile,你可以使用它来构建父模块,只需按以下方式运行profile:mvn clean install -Pparents

从仓库的根目录构建模块

要从仓库的根目录构建特定模块,请在根目录中运行命令:mvn clean install --pl tdd,mockserver -Punit

这里的tdd和mockserver是我们要构建的模块,unit是要执行的测试类型的Maven profile。

运行Spring Boot模块

要运行Spring Boot模块,请在模块目录中运行命令:

mvn spring-boot:run

导入到IDE

该仓库包含大量模块,当你使用单个模块时,无需导入所有模块(或构建所有模块) - 你只需在Eclipse或IntelliJ中导入该特定模块即可。

当你将项目导入到Intellij IDEA中时,默认不会加载任何子模块。你需要在IDE中转到Maven -> Profiles,然后选择你想要构建的子模块所属的profile,最后刷新等待IDE索引构建完成:

运行测试

模块中的命令mvn clean install将运行该模块中的单元测试。对于Spring模块,这也将运行SpringContextTest(如果存在)。

要同时运行单元和集成测试,请使用以下命令:

mvn clean install -Pall

贡献人员


tuyucheng

📆 🚧 🖋

taketoday

🖋

java-testing-ecosystem's People

Contributors

tuyucheng7 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.