Skip to content
☣︎Allows AspectJ Weaving of the class(es) under test at loadtime.
Branch: mirror
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
pom.xml

README.md

org.shaneking.aspectj.helper

The easiest way to test aspectj with junit.

aspectj-junit-runner

Allows AspectJ Weaving of the class(es) under test at loadtime.

Download JAR

or

<dependency>
    <groupId>org.shaneking.aspectj</groupId>
    <artifactId>org.shaneking.aspectj.helper</artifactId>
    <version>0.4.0</version>
</dependency>

To enable AspectJ load time weaving place this annotation on your test class:

@RunWith(AspectJUnit4Runner.class)

Optionally you may want to add something to your classpath for a specific test class. This is maybe the case if you want to put a META-INF/aop.xml file on the classpath for the test. In this case use a combination of these two annotations on your test class:

@RunWith(AspectJUnit4Runner.class)
@AspectJConfig(classpathAdditions = "src/test/hello-resources")

You can also look at the example in the source directory under src/test/java. A very simple example can be found in the test sources in package eu.haobao.junit.aspectj.example.

This JUnit Runner works out of the box in Eclipse and Gradle. But if you run the tests with Maven you will probably have to configure the maven-surefire-plugin. This works for me with Maven, but have a look at this documentation too:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <useSystemClassLoader>true</useSystemClassLoader>
        <useManifestOnlyJar>false</useManifestOnlyJar>
    </configuration>
</plugin>

Any feedback and improvements are welcome!

You can’t perform that action at this time.