AJTE(AspectJ Testing Environment)

AJTE(AspectJ Testing Environment)

AspectJで作られたアスペクトをテストするためのツール.

Download

動作環境

必要な設定

ajte.jarのクラスパスを,aspectjtools.jarよりも先に書く. (aspectjtools.jarの機能の一部を,ajte.jarが上書きしているため.)

典型的な利用方法

 // Logging.aj
 import java.util.*;
 import org.aspectj.lang.annotation.AdviceName;
 
 public aspect Logging{
 	public static List<String> log = new ArrayList<String>();
 
 	pointcut move() : call(void Point.move(int, int));
 
 	before() : move() && this(Line){
 		log.add("calling Point.move()");
 	}
 
 	AdviceName("logging")
 	after() returning : move() && this(Line){
 		log.add("called Point.move()");
 	}
 }
 % java ajte.tool.TestBenchGenerator Logging Logging.aj>LoggingTestBench.java
 // LoggingTestCase.java
 import static ajte.util.Assertion.*;
 import ajte.framework.TestJoinPoint;
 import junit.framework.TestCase;
 
 public class LoggingTestCase extends TestCase{
 	public LoggingTestBench logging= new LoggingTestBench();
 
 	public void setUp(){
 		Logging.log.clear();
 	}
 
 	public void testAdvice1(){
 		logging.beforeMoveAndThisLine();
 		assertEquals(Logging.log.get(0), "calling Point.move()");
 	}
 
 	public void testAdvice2(){
 		logging.logging();
 		assertEquals(Logging.log.get(0), "called Point.move()");
 	}
 
 	public void testPointcut1(){
 		// Yes
 		assertYes(logging.testMove(new TestJoinPoint("call(void Point.move(int, int))", null, null, null)));
 		// No
 		assertNo(logging.testMove(new TestJoinPoint("execution(void Point.move(int, int))", null, null, null)));
 		assertNo(logging.testMove(new TestJoinPoint("call(void Line.move(int, int))", null, null, null)));
 	}
 
 	public void testPointcut2(){
 		// Yes
 		assertYes(logging.testMoveAndThisLine(new TestJoinPoint("call(void Point.move(int, int))", new Line(), null, null)));
 		// No
 		assertNo(logging.testMoveAndThisLine(new TestJoinPoint("call(void Point.move(int, int))", new Point(), null, null)));
 	}
 }
 % javac LoggingTestBench.java LoggingTestCase.java
 % java junit.textui.TestRunner LoggingTestCase
 
 (実行には,テストされるアスペクトへのクラスパスと,テストされるアスペクトのソースファイルへのパスが通っている必要がある.)

Paper

Link