• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

khmarbaise/maven-it-extension: Experimental JUnit Jupiter Extension for writing ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

khmarbaise/maven-it-extension

开源软件地址(OpenSource Url):

https://github.com/khmarbaise/maven-it-extension

开源编程语言(OpenSource Language):

Java 98.6%

开源软件介绍(OpenSource Introduction):

Integration Testing Framework Extension

Apache License, Version 2.0, January 2004 Build Status Site Issues Issues Closed codecov

Release Maven Central Release Notes Users Guide
0.11.0 Maven Central PDF PDF
HTML HTML
0.12.0-SNAPSHOT Maven Central PDF PDF
HTML HTML

State

The project is in an early state but already being useful and can be used for real testing. The project release is available via Central repository (only the given version as show in above table) which makes it easy for you to use it out without the need to compile the code (You can of course do that if you like) yourself.

General Overview

The basic thing about integration testing of Maven Plugins / Maven Extensions etc. is currently that the existing solutions are not a very concise and comprehensive which is based on the long development history of the Apache Maven project. There are a lot of different approaches done over the time but from my perspective they all lack one thing: Simplicity. More detailed reasons etc. can be read in the Background Guide. This is the reason why I think it's time to come up with a more modern setup and started this project.

The Basic Idea

The basic idea rest upon the option to write custom extension with JUnit Jupiter for JUnit Jupiter testing framework which makes it very easy to get things done.

So in general the whole Integration Testing Framework in its core (itf-jupiter-extension) is a JUnit Jupiter extension which delivers supplemental support for a testing framework in general and in particular for using integration tests. Of course there is a lot of convenience integrated into it to make integration testing of Maven plugins easier.

Quick Start

The General Requirements

The requirements to write integration tests with the integration testing framework are the following:

  • JDK8+
  • Apache Maven 3.8.4 or above.

The Maven Configuration

The first thing before you can run integration tests is to add the following dependencies (as minimum) to your pom.xml:

<project..>
   ...
  <dependencies>
   <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.soebes.itf.jupiter.extension</groupId>
      <artifactId>itf-jupiter-extension</artifactId>
      <version>0.11.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
     <groupId>com.soebes.itf.jupiter.extension</groupId>
     <artifactId>itf-assertj</artifactId>
     <version>0.11.0</version>
     <scope>test</scope>
    </dependency>
  </dependencies>
  ..
</project..>

The first dependency org.junit.jupiter:junit-jupiter-engine is needed for JUnit Jupiter (We recommend the most recent version) working and the second one com.soebes.itf.jupiter.extension:itf-jupiter-extension is the extension to get support for running in general integration tests as described later. Finally, you have to add com.soebes.itf.jupiter.extension:itf-assertj which contains custom assertions based on AssertJ.

The next part is to add itf-maven-plugin in your pom.xml file like this which handles the first part which is involved:

<project...>
  ..
  <build>
    ..
    <plugin>
      <groupId>com.soebes.itf.jupiter.extension</groupId>
      <artifactId>itf-maven-plugin</artifactId>
      <version>0.11.0</version>
      <executions>
        <execution>
          <id>installing</id>
          <phase>pre-integration-test</phase>
          <goals>
            <goal>install</goal>
            <goal>resources-its</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ..
  </build>
  ..
</project...>

The given version of itf-jupiter-extension as well as itf-maven-plugin should always be the most recent version which is available via Central repository.

Based on the concept we would like to run integration identified by the naming convention we have to add the maven-failsafe-plugin to the pom.xml like this (This will execute the integration tests which checks the functionality; The second part which is involved).

<project...>
  ..
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
      <!--
       ! currently needed to run integration tests.
      -->
      <systemProperties>
        <maven.version>${maven.version}</maven.version>
        <maven.home>${maven.home}</maven.home>
      </systemProperties>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>integration-test</goal>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</project...>

Details about the given configuration can be read in the users guide.

The Involved Parties

Writing an integration test for a Maven plugin means you have to have three parties:

  1. The component you would like to test (typically a Maven plugin etc.).
  2. The testing code where you check the functionality.
  3. The Project you would like to test with (where your Maven plugin usually is configured in to be used.)

The Component code

The component you write is located in your project in the usual location. This is of course only an example of how it looks like in reality (usually more classes etc.):

.
└── src/
    └── main/
        └── java/
            └── org/
                └── plugin/
                    └── PluginMojo.java

The Testing Code

The structure for an integration tests follows of course the convention over configuration paradigm. Based on the conventions in Maven an integration test should be named like *IT.java and be located in the directory structure as follows:

.
└── src/
    └── test/
        └── java/
            └── org/
                └── it/
                    └── FirstMavenIT.java

So now the real a test code looks like this:

package org.it;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;

import com.soebes.itf.jupiter.extension.MavenJupiterExtension;
import com.soebes.itf.jupiter.extension.MavenTest;
import com.soebes.itf.jupiter.maven.MavenExecutionResult;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;

@MavenJupiterExtension // <1>
public class FirstMavenIT {

 @MavenTest // <2>
 void the_first_test_case(MavenExecutionResult result) { // <3>
  assertThat(result).isSuccessful(); // <4>
 }
 
}
  1. Maven Integration test annotation.
  2. Maven Test Annotation.
  3. Injected execution result
  4. Custom assertions to check the result of the build.

The Project to Test With

The project you would like to use as a foundation for your test of the plugin. This is located in a special location under src/test/resources-its/... This is needed to prevent the confusion with the usual src/test/resources in particular related to filtering etc. (details about the setup etc. in the users guide).

.
└── src/
    └── test/
        └── resources-its/
            └── org/
                └── it/
                    └── FirstMavenIT/
                        └── the_first_test_case/
                            ├── src/
                            └── pom.xml

The Executed Test

After execution of the integration test the result will look like this:

.
└──target/
   └── maven-it/
       └── org/
           └── it/
               └── FirstMavenIT/
                   └── the_first_test_case/
                       ├── .m2/
                       ├── project/
                       │   ├── src/
                       │   ├── target/
                       │   └── pom.xml
                       ├── mvn-stdout.log
                       ├── mvn-stderr.log
                       ├── mvn-arguments.log
                       └── orther logs.

This gives you a first impression how an integration test can look like. There are a lot of example in this project available and of course I strongly recommend reading the documentation (I know I don't like reading documentation either).

Conclusion

If you like the framework don't hesitate to test and give feedback in particular if things don't work as described or as you expected them to work.

Building

If you like to build the project from source yourself you need the following:

  • JDK 17+
  • Apache Maven 3.8.4+

The whole project can be built via:

mvn clean verify

This will take some time cause there are already integration tests in the itf-examples project which are executed and real integration tests for the itf-maven-plugin which is a bootstrap (eat-your-own-dog-food) to use already parts of the framework (JUnit Jupiter extension) to make the development of the plugin easier.

Concept and Background Guide

The concept guide describe my ideas I have in mind (just not to forget them). It is neither a roadmap nor about future releases etc. It's only intended to keep my ideas at a central location.

  • PDF
  • HTML

The background guide is a conclusion about the reason why I have started this project.

  • PDF
  • HTML

GitHub Pages

Currently we have two states of site:




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
alexcojocaru/elasticsearch-maven-plugin: A Maven plugin to run a single node Ela ...发布时间:2022-08-16
下一篇:
geb/geb-example-maven发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap