Skip to content

runforesight/jexter

Repository files navigation

Jexter

Build Status License Lifecycle

Extensions/Plugins for JVM test frameworks (JUnit 4, JUnit 5, ...)

Get Jexter

Binaries are available from Maven Central.

Group Artifact Latest Stable Version
io.thundra jexter-* Maven Central

For Maven:

<dependency>
	<groupId>io.thundra</groupId>
	<artifactId>jexter-...</artifactId>
	<version><!--...--></version>
	<scope>test</scope>
</dependency>

For Gradle:

testCompile group: 'io.thundra', name: 'jexter-...', version: /*...*/

Below are the various artifacts published:

Artifact Description
jexter-core Core module
jexter-junit4-core JUnit4 core module
jexter-junit5-core JUnit5 core module

Versioning

Artifact versions are in X.Y.Z format

  • X: Major version number.
    • Increases only when there are big API and/or architectural changes.
    • Breaks backward compatibility.
  • Y: Minor version number.
    • Increases for small API changes and big improvements.
    • Breaks backward compatibility.
  • Z: Patch version number.
    • Increases for bug fixes and small improvements.
    • Doesn’t break backward compatibility.

Requirements

  • JDK 1.8+ (for build and execution)
  • Maven 3.x (for build)

Build

To build:

$ git clone git@github.com:thundra-io/jexter.git
$ cd jexter/
$ mvn clean install

How to Use

Utilities/Helpers

EnvironmentVariableHelper

Set environment variable
import io.thundra.jexter.core.envvar.EnvironmentVariableHelper;

...

EnvironmentVariableHelper.set("env-var-name", "env-var-value");
Remove environment variable
import io.thundra.jexter.core.envvar.EnvironmentVariableHelper;

...

EnvironmentVariableHelper.remove("env-var-name");

JUnit 4 Rules

EnvironmentVariableSandboxRule

Stores environment variables before the test and restores them back to original value after the test.

  • Add jexter-junit4-core dependency
  • Define EnvironmentVariableSandboxRule as test or class level rule

Method level:

import io.thundra.jexter.junit4.core.envvar.EnvironmentVariableSandboxRule;

...

public class TheTest {

    ...

    @Rule
    public EnvironmentVariableSandboxRule rule = new EnvironmentVariableSandboxRule();

    ...

}

Class level:

import io.thundra.jexter.junit4.core.envvar.EnvironmentVariableSandboxRule;

...

public class TheTest {

    ...

    @ClassRule
    public static EnvironmentVariableSandboxRule rule = new EnvironmentVariableSandboxRule();

    ...

}

SystemPropertySandboxRule

Stores system properties before the test and restores them back to original value after the test.

  • Add jexter-junit4-core dependency
  • Define SystemPropertySandboxRule as test or class level rule

Method level:

import io.thundra.jexter.junit4.core.sysprop.SystemPropertySandboxRule;

...

public class TheTest {

    ...

    @Rule
    public SystemPropertySandboxRule rule = new SystemPropertySandboxRule();

    ...

}

Class level:

import io.thundra.jexter.junit4.core.sysprop.SystemPropertySandboxRule;

...

public class TheTest {

    ...

    @ClassRule
    public static SystemPropertySandboxRule rule = new SystemPropertySandboxRule();

    ...

}

StopwatchRule

Measures the elapsed time of a test or test suite (class) execution.

  • Add jexter-junit4-core dependency
  • Define StopwatchRule as test or class level rule

Method level:

import io.thundra.jexter.junit4.core.sw.StopwatchRule;

...

public class TheTest {

    ...

    @Rule
    public StopwatchRule rule = new StopwatchRule();

    ...

}

Class level:

import io.thundra.jexter.junit4.core.sw.StopwatchRule;

...

public class TheTest {

    ...

    @ClassRule
    public static StopwatchRule rule = new StopwatchRule();

    ...

}

JUnit 5 Extension

EnvironmentVariableSandboxExtension

Stores environment variables before the test and restores them back to original value after the test.

  • Add jexter-junit5-core dependency
  • Annotate test method or class by @EnvironmentVariableSandbox annotation

Method level:

import io.thundra.jexter.junit5.core.envvar.EnvironmentVariableSandbox;

...

public class TheTest {

    ...

    @EnvironmentVariableSandbox
    @Test
    public void test() {
        ...
    }

    ...

}

Class level:

import io.thundra.jexter.junit5.core.envvar.EnvironmentVariableSandbox;

...

@EnvironmentVariableSandbox
public class TheTest {

    ...

    @Test
    public void test() {
        ...
    }

    ...

}

SystemPropertySandboxExtension

Stores system properties before the test and restores them back to original value after the test.

  • Add jexter-junit5-core dependency
  • Annotate test method or class by @SystemPropertySandbox annotation

Method level:

import io.thundra.jexter.junit5.core.sysprop.SystemPropertySandbox;

...

public class TheTest {

    ...

    @SystemPropertySandbox
    @Test
    public void test() {
        ...
    }

    ...

}

Class level:

import io.thundra.jexter.junit5.core.sysprop.SystemPropertySandbox;

...

@SystemPropertySandbox
public class TheTest {

    ...

    @Test
    public void test() {
        ...
    }

    ...

}

StopwatchExtension

Measures the elapsed time of a test or test suite (class) execution.

  • Add jexter-junit5-core dependency
  • Annotate test method or class by @Stopwatch annotation

Method level:

import io.thundra.jexter.junit5.core.sw.Stopwatch;

...

public class TheTest {

    ...

    @Stopwatch
    @Test
    public void test() {
        ...
    }

    ...

}

Class level:

import io.thundra.jexter.junit5.core.sw.Stopwatch;

...

@Stopwatch
public class TheTest {

    ...

    @Test
    public void test() {
        ...
    }

    ...

}

Issues and Feedback

Issues Closed issues

Please use GitHub Issues for any bug report, feature request and support.

Contribution

Pull requests Closed pull requests Contributors

If you would like to contribute, please

  • Fork the repository on GitHub and clone your fork.
  • Create a branch for your changes and make your changes on it.
  • Send a pull request by explaining clearly what is your contribution.

Tip: Please check the existing pull requests for similar contributions and consider submit an issue to discuss the proposed feature before writing code.

LICENSE

Copyright (c) 2018 Thundra, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.