AJTE(AspectJ Testing Environment)
AJTE(AspectJ Testing Environment)
AspectJで作られたアスペクトをテストするためのツール.
Download
- version 0.2.4 : 2005/09/26
- version 0.2.3 : 2005/09/25
- version 0.2.2 : 2005/09/24
- version 0.2.1 : 2005/09/22
- version 0.2.0 beta : 2005/09/18
- version 0.1.2 : 2005/09/16
動作環境
- AspectJ1.5M3a (M4では動きません)
必要な設定
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()");
}
}
- ajte.tool.TestBenchGeneratorを実行して,アスペクトのテスト用クラス(TestBench)を生成する.
% java ajte.tool.TestBenchGenerator Logging Logging.aj>LoggingTestBench.java
- TestBenchに書かれているメソッドをテストするテストケースを書く.
// 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)));
}
}
- TestBenchとテストケースをコンパイルして,テストケースを実行する.
% javac LoggingTestBench.java LoggingTestCase.java % java junit.textui.TestRunner LoggingTestCase (実行には,テストされるアスペクトへのクラスパスと,テストされるアスペクトのソースファイルへのパスが通っている必要がある.)
Paper
-
Yudai Yamazaki , Kouhei Sakurai , Saeko Matsuura , Hidehiko Masuhara , Hiroaki Hashiura , Seiichi Komiya ,
A Unit Testing Framework for Aspects without Weaving
Workshop on Testing Aspect-Oriented Programs (WTAOP) , pp. , 2005 , WTAOP_withoutweaving.pdf WTAOP_withoutweaving.ppt