Maven Plugin to run OOT tests

Object Oriented Testing Framework Maven parent

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

wtf.g4s8.oot
ArtifactId

ArtifactId

oot-maven-plugin
Last Version

Last Version

0.1.7
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Maven Plugin to run OOT tests
Object Oriented Testing Framework Maven parent
Source Code Management

Source Code Management

https://github.com/g4s8/oot/tree/master/oot-maven-plugin

Download oot-maven-plugin

How to add to project

<plugin>
    <groupId>wtf.g4s8.oot</groupId>
    <artifactId>oot-maven-plugin</artifactId>
    <version>0.1.7</version>
</plugin>

Dependencies

provided (5)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.3.9
org.apache.maven : maven-core jar 3.3.9
org.apache.maven : maven-artifact jar 3.3.9
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0
org.apache.maven : maven-model jar 3.3.9

test (3)

Group / Artifact Type Version
org.apache.maven : maven-compat jar 3.3.9
junit : junit jar 4.12
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0

Project Modules

There are no modules declared in this project.

Experimental Object Oriented Testing Framework for Java

EO principles respected here DevOps By Rultor.com

oot: Maven Central, oot-maven-plugin: Maven Central

Build Status Build status CircleCI PDD status License

Concepts

  1. Use single entry points for all tests
  2. Use composition to construct test cases
  3. Control test runs behavior in the code
  4. Write test-cases objects instead of classes with test functions

Prerequirements

Usage

Disable maven-surefire-plugin by adding skipTests property to configuration, add oot-maven-plugin and oot library dependency to pom.xml:

<project>
  <dependencies>
    <dependency>
      <groupId>wtf.g4s8.oot</groupId>
      <artifactId>oot</artifactId>
      <!-- use latest release version or add snapshots repo -->
      <version>1.0-SNAPSHOT</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
      <plugin>
        <groupId>wtf.g4s8.oot</groupId>
        <artifactId>oot-maven-plugin</artifactId>
        <!-- use latest release version or add snapshots repo -->
        <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Maven Plugin will be executed on test phase, supported properties are:

  • skipTests - disable tests (optional, default false)

It will search for public class with public static void test method, same as java cli searches for main method.

Hint: check ./oot-example project for real example Maven project.

To write first test, create public test class with method test:

public final MainTest {
  public static void test() {
    // run tests here
  }
}

oot library use TestReport implementations to report test results and fail test phase on test failure. And TestCase implementation to wrap test logic:

public final MainTest {
  public static void test() {
    try (FailingReport report = new FailingReport(new ConsoleReport())) {
      new SimpleTest<>("basic test", () -> 1 + 1, Matchers.is(2));
    }
  }
}

In this example:

  • FailingReport will fail test phase after all tests if any test fails
  • ConsoleReport will print all test results to stdout
  • SimpleTest - generic object to apply Hamcrest matcher to target object

To run multiple tests sequentially use:

new SequentialTests(
  new FooTest(),
  new BarTest(),
  new BazTest()
)

To run it parallelly use:

new ParallelTests(
  new FooTest(),
  new BarTest(),
  new BazTest()
)

Decorating

TestCase has default decorator TestCase.Wrap. It can be used to move all tests composition into main test constructor:

public final class MainTest extends TestCase.Wrap {
  private MainTest() {
    super(
      new ParallelTests(
        new TestOne(),
        new TestTwo(),
        new TestThree()
      )
    );
  }

  public static void test() throws IOException {
    try (FailingReport report = new FailingReport(new ConsoleReport())) {
      new MainTest().run(report);
    }
  }
}

Versions

Version
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3