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. Those types can also be used with the JUnit 5 library. Please read how to use the "utils" module.
<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>
<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>
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 The module was also tested for compatibility with the Byteman in version 4.10.0. It means that the module can be used together with the JUnit 5 library.
The project contains few modules with tests which demonstrates how to use static methods of type BMUnitUtils with JUnit 4, JUnit5 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
- JUnit5 test which use restTemplate component and "joins" mechanism
- If you facing any issues related with project usage please check on wiki page if there is already a solution for your problem
- Any new issues please report in GitHub site