Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/exasol/maven-plugin-integration-testing
Library for writing integration tests for maven plugins.
https://github.com/exasol/maven-plugin-integration-testing
exasol-integration integration-testing maven maven-plugin
Last synced: 5 days ago
JSON representation
Library for writing integration tests for maven plugins.
- Host: GitHub
- URL: https://github.com/exasol/maven-plugin-integration-testing
- Owner: exasol
- License: mit
- Created: 2021-04-28T07:35:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-11T08:52:49.000Z (5 months ago)
- Last Synced: 2024-06-11T10:16:39.689Z (5 months ago)
- Topics: exasol-integration, integration-testing, maven, maven-plugin
- Language: Java
- Homepage:
- Size: 72.3 KB
- Stars: 1
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Maven Plugin Integration Testing
Java library for writing integration tests for maven plugins.
[![Build Status](https://github.com/exasol/maven-plugin-integration-testing/actions/workflows/ci-build.yml/badge.svg)](https://github.com/exasol/maven-plugin-integration-testing/actions/workflows/ci-build.yml)
[![Maven Central – Maven Plugin Integration Testing](https://img.shields.io/maven-central/v/com.exasol/maven-plugin-integration-testing)](https://search.maven.org/artifact/com.exasol/maven-plugin-integration-testing)[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=security_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=sqale_index)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=code_smells)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=coverage)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Amaven-plugin-integration-testing&metric=ncloc)](https://sonarcloud.io/dashboard?id=com.exasol%3Amaven-plugin-integration-testing)## Features
* Run tests with isolated local repository (the plugin won't be installed in your default local maven repository)
* Extract code coverage
* Debug## Usage
The following code snippet gives an example on how the `MavenIntegrationTestEnvironment` is typically used.
Note that this is only an example. To make it work with your plugin you need to change `MY_PLUGIN_JAR` and the calls of `verifier`.
```java
private class MyPluginTest {
private static final File MY_PLUGIN_JAR = new File("target/dummy-plugin-0.1.0.jar");
private static final File MY_PLUGIN_POM = new File("pom.xml");
private static MavenIntegrationTestEnvironment testEnvironment;@BeforeAll
static void beforeAll() {
testEnvironment = new MavenIntegrationTestEnvironment();
testEnvironment.installPlugin(MY_PLUGIN_JAR, MY_PLUGIN_POM);
}@Test
void testInstallAndRunPlugin(@TempDir final Path tempProjectDir) throws IOException, VerificationException {
writePomFile(tempProjectDir);
final Verifier verifier = testEnvironment.getVerifier(tempDir);
verifier.executeGoal("com.example:my-plugin:hello");
verifier.verifyTextInLog("Hello World!");
}/**
* Write an example pom.xml to the test-project.
*
* The pom file should use your plugin.
*
* @param tempProjectDir temporary test project folder to write the pom file to
* @throws IOException if write fails
*/
private void writePomFile(final Path tempProjectDir) throws IOException {
Files.copy(
Objects.requireNonNull(
getClass().getClassLoader().getResourceAsStream("test-project/pom.xml")),
tempProjectDir.resolve("pom.xml"), StandardCopyOption.REPLACE_EXISTING);
}
}
```For a working example check [`MavenIntegrationTestEnvironmentIT.java`](src/test/java/com/exasol/mavenpluginintegrationtesting/MavenIntegrationTestEnvironmentIT.java).
### Options
You can configure the verifier using system properties at runtime. By that you don't need to change your code for example to enable debugging. You simply add a command line parameter to the JVM options of the run command in your IDE. You can also define different run profiles in your IDE (e.g. run with debugging enabled).
#### Debugging
To enable debugging append `-Dtest.debug=true` to your JVM options. This library will then configure the `Validator` to start maven with debugging enabled. This will cause maven to wait on an incoming debugger connection on port 8000. After you have started the tests, you'll be able to connect to localhost:8000 using the remote-debugger of your IDE.
Note: The tests will wait for the debugger. So if you don't connect, the tests will not run.
#### Coverage:
You can enable the extraction of code coverage information by adding `-Dtest.coverage=true` to your JVM call. This library will then add a jacoco-agent from `target/jacoco-agent/org.jacoco.agent-runtime.jar` to the JVMs of the maven processes started by the `Verifier`.
For this to work we need to place the jacoco agent there. We can do so using `maven-dependency-plugin`. Check out this repository's [`pom.xml`](./pom.xml) for an example. If you use [project-keeper][project-keeper] simply add the `udf-coverage` module.
This agent will then write the coverage information to `target/jacoco-mvn-NUMBER-.exec` files. In order to create a report or send it to sonar you have to merge these executions into one. You can do so using the `jacoco-maven-plugin`. If you are using [project-keeper][project-keeper] simply add the `udf-coverage` module.
## Additional Information
* [Changelog](doc/changes/changelog.md)
* [Dependencies](dependencies.md)[project-keeper]: https://github.com/exasol/project-keeper-maven-plugin/