Support of junit4 rule for the bmunit library.
Project contains junit4 rule which allows integration with byteman framework and use it in junit and spock tests. Enables to use bmunit library in test executed by SpringRunner and Spock tests runner. It also contains types which allows to operate on mechanisms like counters, rendezvous, joins in the tests methods.
Project is published in Bintray repository. To download dependencies it is required to add information about repository in "pom.xml" file. Project is also available from other repositories.
<project>
...
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-starnowski-bmunit-extension</id>
<name>bintray</name>
<url>https://dl.bintray.com/starnowski/bmunit-extension</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-starnowski-bmunit-extension</id>
<name>bintray-plugins</name>
<url>https://dl.bintray.com/starnowski/bmunit-extension</url>
</pluginRepository>
</pluginRepositories>
...
</project>
Or add this information in maven "settings.xml" file.
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-starnowski-bmunit-extension</id>
<name>bintray</name>
<url>https://dl.bintray.com/starnowski/bmunit-extension</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-starnowski-bmunit-extension</id>
<name>bintray-plugins</name>
<url>https://dl.bintray.com/starnowski/bmunit-extension</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>
<dependency>
<groupId>com.github.starnowski.bmunit.extension</groupId>
<artifactId>junit4-rule</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-bmunit</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
To add module "com.github.starnowski.bmunit.extension:junit4-rule" as dependency in local maven repository, attach repository information or build project locally.
<dependency>
<groupId>com.github.starnowski.bmunit.extension</groupId>
<artifactId>utils</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-submit</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-install</artifactId>
<version>3.0.10</version>
<scope>test</scope>
</dependency>
To add module "com.github.starnowski.bmunit.extension:utils" as dependency in local maven repository, attach repository information or build project locally.
Build parent project with maven
mvn clean install
To have ability to use anotations " org.jboss.byteman.contrib.bmunit.BMUnitConfig", "org.jboss.byteman.contrib.bmunit.BMRule" and "org.jboss.byteman.contrib.bmunit.BMRules" add the object of "com.github.starnowski.bmunit.extension.junit4.rule.BMUnitMethodRule" type into the test class.
import com.github.starnowski.bmunit.extension.junit4.rule.BMUnitMethodRule;
import org.junit.Rule;
...
@Rule
public BMUnitMethodRule bmUnitMethodRule = new BMUnitMethodRule();
Project contains few modules with tests which demonstrates how to use the BMUnitMethodRule rule with junit4 tests and spock framework tests:
Module "utils" contains object type "com.github.starnowski.bmunit.extension.utils.BMUnitUtils" which contains static methods. Methods allows to operate on mechanism like counters, rendezvous, joins. Thanks to this methods you can manipulate on those objects from tests level
Project contains few modules with tests which demonstrates how to use static methods of type BMUnitUtils with junit4 tests and spock framework tests:
- Module "junit4-rule-demo" contains use case which demonstrate how use BMUnitMethodRule without BMUnitRunner
- Module "junit4-rule-utils-demo" contains use cases which demonstrate how use BMUnitMethodRule without BMUnitRunner. It shows also usage of components from module "utils"
- Module "junit4-spock-spring-demo" contains use cases for junit and spock framework tests which use integration with spring framework
- Junit4 test with SpringRunner which use restTemplate component and "joins" mechanism
- Junit4 tests with SpringRunner which use "joins" and "rendezvous" mechanisms to test asynchronous operations
- Spock test which use BMUnitMethodRule to override static method
- Spock test with SpringRunner which use "joins" mechanism
- Spock test with SpringRunner which use restTemplate component and "joins" mechanism
Project is also published in jcenter repository. To use it you have to attach repository in project descriptor or the maven settings.
<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray-plugins</name>
<url>https://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>