byteman-junit-rules

This project contains functionality allowing the usage of byteman in JUnit tests by providing JUnit rules (install byteman agent, load/unload of the rules) and some annotations (byteman setup for the tests).

License

License

Categories

Categories

JUnit Unit Testing Byteman Application Layer Libs Bytecode Manipulation
GroupId

GroupId

com.github.mahnkong
ArtifactId

ArtifactId

byteman-junit-rules
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

byteman-junit-rules
This project contains functionality allowing the usage of byteman in JUnit tests by providing JUnit rules (install byteman agent, load/unload of the rules) and some annotations (byteman setup for the tests).
Project URL

Project URL

https://github.com/mahnkong/byteman-junit-rules
Source Code Management

Source Code Management

https://github.com/mahnkong/byteman-junit-rules

Download byteman-junit-rules

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mahnkong/byteman-junit-rules/ -->
<dependency>
    <groupId>com.github.mahnkong</groupId>
    <artifactId>byteman-junit-rules</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mahnkong/byteman-junit-rules/
implementation 'com.github.mahnkong:byteman-junit-rules:1.0.3'
// https://jarcasting.com/artifacts/com.github.mahnkong/byteman-junit-rules/
implementation ("com.github.mahnkong:byteman-junit-rules:1.0.3")
'com.github.mahnkong:byteman-junit-rules:jar:1.0.3'
<dependency org="com.github.mahnkong" name="byteman-junit-rules" rev="1.0.3">
  <artifact name="byteman-junit-rules" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mahnkong', module='byteman-junit-rules', version='1.0.3')
)
libraryDependencies += "com.github.mahnkong" % "byteman-junit-rules" % "1.0.3"
[com.github.mahnkong/byteman-junit-rules "1.0.3"]

Dependencies

runtime (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.jboss.byteman : byteman-submit jar 3.0.6

Project Modules

There are no modules declared in this project.

Travis build status Download

byteman-junit-rules

This project contains functionality allowing the usage of byteman in JUnit tests by providing JUnit rules (install byteman agent, load/unload of the rules) and some annotations (byteman setup for the tests). Byteman can also be used in JUnit tests by using the BMUnitRunner class provided by byteman, but this will prevent the usage of other runners (i.e. the Arquillian runner)

The project requires byteman to be installed on the machine where the tests are executed. The path to byteman can be set as environment variable (BYTEMAN_HOME), so the rules will find it without specifying any parameter. Additionally, the path to byteman can also be specified when creating the rule objects.

The versions used developing (and testing) this project were:

  • Junit: 4.12
  • Byteman: 3.0.6

BytemanAgentInstaller

This rule installs the byteman agent into the JVM of the test. This rule must be annotated as ClassRule, so that the agent gets installed only once into the JVM!

The builder allows the setting of the following options:

  • bytemanHome: specifies the path to byteman
  • bindAddress: address that the listener binds itself to (default = localhost)
  • bindPort: port that the listener binds itself to (default = 9091)
  • verbose: adds verbosity option to the agent installation (-Dorg.jboss.byteman.verbose)
  • verbose: adds debug option the agent installation (-Dorg.jboss.byteman.debug)
  • installIntoBootstrapClasspath: installs the byteman agent into the bootstrap classpath (bminstall -b)
  • accessAllAreas: sets an access-all-areas security policy for the byteman rules (bminstall -s)
  • transformAll: sets the "-Dorg.jboss.byteman.transform.all" property when installing the agent (see byteman docs for more details)

Example definition inside a test case:

public class MyTest {

  @ClassRule
  public static BytemanAgentInstaller bytemanAgentInstaller = new BytemanAgentInstaller.Builder().build();

}

BytemanRuleSubmitter

This rule loads the byteman rules specified for the tests into the byteman agent and unloads them on test completion.

The builder allows the setting of the following options:

  • bytemanHome: specifies the path to byteman

Example definition inside a test case:

public class MyTest {

  @Rule
  public BytemanRuleSubmitter bytemanRuleSubmitter = new BytemanRuleSubmitter.Builder().build();
    
}

Annotations for the use of byteman

2 annotations exist for setting up the test class and test methods for the use of byteman:

BytemanRuleFile

This annotation can be applied to classes and methods and specifies the rules to be loaded into the byteman agent before executing the test. Currently there exist 2 options to the annotation:

  • filepath: mandatory, specifies where to find the rule file (can be relative to the project directory)

Rules configured on class level are loaded before each test and unloaded afterwards. Rules configured on method level are loaded only before the test they are annotated to and unloaded after test execution. If the test class and the test method are both annotated with BytemanRuleFile, first the class rules are loaded and afterwards the method rules. Then again the test gets executed and afterwards the method rules are unloaded before the class rules.

Example definition inside a test case (the rules here are stored inside src/test/resources and therefore get copied to target/test-classes:

@BytemanRuleFile(filepath = "target/test-classes/myclassrule.btm")
public class MyTest {

  @Test
  @BytemanRuleFile(filepath = "target/test-classes/mymethodrule.btm")
  public void myTestMethod() {
    //the test
  }
}

IgnoreBytemanClassRuleFile

This annotation can be applied to methods and specifies, that for the test it is annotated on no class level rules get executed (only the test method rules are applied)

Example definition inside a test case:

@BytemanRuleFile(filepath = "target/test-classes/myclassrule.btm")
public class MyTest {

  @Test
  @BytemanRuleFile(filepath = "target/test-classes/mymethodrule.btm")
  @IgnoreBytemanClassRuleFile
  public void myTestMethod() {
    //the test
  }
}

Please check the integration tests (*IT.java) for complete examples showing how to utilise the project.

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0