I have an aspect code like this:
package aspects;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.aspectj.lang.Signature;
import org.junit.Test;
public aspect TestCaseTrace{
// pointcut traceTestCase() : (execution(public * test*(..)));
pointcut traceTestCase() : (execution(@Test * *(..)));
before(): traceTestCase(){
String sourceName = thisJoinPointStaticPart.getSourceLocation().getWithinType().getCanonicalName();
Signature sig = thisJoinPointStaticPart.getSignature();
System.out.println("Test case name is " + sig.getDeclaringTypeName() + "." + sig.getName() + "\n\n");
}
after(): traceTestCase(){
// Logger.getLogger("Tracing").log(Level.INFO,"Test case got over\n\n");
System.out.println("Test case got over\n\n");
}
}
I'm trying to trace the junit @Test
in the above code. While I compile the aspect, with the below command:
ajc -classpath aspectjrt.jar:junit-4.10.jar -outxml -outjar aspects.jar TestCaseTrace.java
but this command gives an error like this:
TestCaseTrace.java:13 [error] annotation type patterns are only supported at Java 5 compliance level or above
pointcut traceTestCase() : (execution(@Test * *(..)));
1 error
where I'm making the mistake?
Java version used is 1.7 and aspect version is 1.8.6
Edit:
After following the answer I could able to compile with warnings. But after that if I use the resulting aspect.jar
to inspect the junit test case:
import org.junit.Test;
class HelloWorldApp {
@Test
public void testSome()
{
A.methodA();
}
}
class A{
public static void methodA()
{
methodB();
}
public static void methodB()
{
}
}
and run with the command line:
java -javaagent:aspectjweaver.jar -cp aspects.jar:. HelloWorldApp
Nothing is getting printed.