java - AspectJ with JUnit tests by inpathing the main project -


i have downloaded large project (whiley) , wanting trace every method executed during projects junit tests.

there 6 modules , rely on each other mostly.

i trying single module working using eclipse aspectj plugin.

my aspectj inpath settings

inpath settings

aspectj weaves code , produces compiled version of wyc in /bin folder.

however, when try , run junit test's .class file through cli.

with following statement:

java -cp "c:\users\name\git\whileycompiler\lib\junit-4.11.jar";"c:\users\name\git\whileycompiler\lib\*.jar";"c:\users\name\git\whileycompiler\lib\hamcrest-all-1.3.jar" org.junit.runner.junitcore "c:\users\name\git\test\bin\wyc\testing\allvalidtests.class" 

i following:

error

my aspect file

    pointcut tracemethods() : (execution(* *(..))&& !cflow(within(trace)));  before(): tracemethods(){     signature sig = thisjoinpointstaticpart.getsignature();     string line =""+ thisjoinpointstaticpart.getsourcelocation().getline();     string sourcename = thisjoinpointstaticpart.getsourcelocation().getwithintype().getcanonicalname();     service.addmethodcall(sourcename);     logger.getlogger("tracing").log(             level.info,             "call "                 +  sourcename                 +" line " +                 line                 +" " +sig.getdeclaringtypename() + "." + sig.getname()     ); } 

four things note:

  • user hoàng long right, need specify qualified class name instead of path junit runner.
  • this means need add path test classes classpath.
  • in classpath cannot use *.jar, use * wildcard, see this answer.
  • furthermore, if want use precompiled aspectj aspects, need add aspectj runtime aspectjrt.jar classpath.

here example of how run junit in case. added line breaks make more readable, needs on 1 line:

java     -cp         "c:\users\name\git\whileycompiler\lib\junit-4.11.jar";         "c:\users\name\git\whileycompiler\lib\*";         "c:\users\name\git\whileycompiler\lib\hamcrest-all-1.3.jar";         "c:\users\name\git\whileycompiler\lib\aspectjrt.jar";         "c:\users\name\git\test\bin"     org.junit.runner.junitcore         wyc.testing.allvalidtests 

update:

actually busy week, gave quick try here ltw on binary jars, *.whiley test files unpacked. works nicely, see log output on console. had change pointcut though because lead bloated output in ltw scenario when loaded framework classes (e.g. junit) woven. simplified aspect bit in order provide formatted output on system.out directly instead of logging overhead timestamps because found more readable.

modified aspect:

package de.scrum_master.aspect;  public aspect traceaspect {     pointcut tracemethods() :         execution(* *(..)) && (within(whiley..*) || within(wy*..*));      before() : tracemethods() {         system.out.printf(             "%40s | %s%n",             thisjoinpoint.getsourcelocation(),             thisjoinpoint.getsignature()          );     } } 

console output:

junit version 4.11 .                 allvalidtests.java:2729 | void wyc.testing.allvalidtests.typeequals_valid_1()                    allvalidtests.java:97 | void wyc.testing.allvalidtests.runtest(string)                        testutils.java:28 | pair wyc.testing.testutils.compile(string[])                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                        pipeline.java:292 | void wycc.lang.pipeline.register(class)                         content.java:135 | content.filter wyfs.lang.content.filter(string, content.type)                            trie.java:238 | trie wyfs.util.trie.fromstring(string)                            trie.java:193 | trie wyfs.util.trie.append(string)                            trie.java:312 | int wyfs.util.trie.binarysearch(trie[], int, string)                         content.java:135 | content.filter wyfs.lang.content.filter(string, content.type)                            trie.java:238 | trie wyfs.util.trie.fromstring(string)                            trie.java:193 | trie wyfs.util.trie.append(string)                            trie.java:312 | int wyfs.util.trie.binarysearch(trie[], int, string)                         content.java:135 | content.filter wyfs.lang.content.filter(string, content.type)                            trie.java:238 | trie wyfs.util.trie.fromstring(string)                            trie.java:193 | trie wyfs.util.trie.append(string)                            trie.java:312 | int wyfs.util.trie.binarysearch(trie[], int, string)                      virtualroot.java:50 | virtualroot.folder wyfs.util.virtualroot.root()                      virtualroot.java:50 | virtualroot.folder wyfs.util.virtualroot.root()                      virtualroot.java:50 | virtualroot.folder wyfs.util.virtualroot.root()                         wycmain.java:179 | int wyc.wycmain.run(string[])                          optarg.java:322 | map wycc.util.optarg.parseoptions(list, optarg[])                          optarg.java:218 | void wycc.util.optarg.filedir.process(string, string, map)                          optarg.java:231 | void wycc.util.optarg.filelist.process(string, string, map)                         wycmain.java:258 | void wyc.wycmain.configure(map)                    wycbuildtask.java:331 | void wyc.util.wycbuildtask.setverbose(boolean)                    wycbuildtask.java:335 | void wyc.util.wycbuildtask.setverification(boolean)                    wycbuildtask.java:343 | void wyc.util.wycbuildtask.setsmtverification(boolean)                    wycbuildtask.java:339 | void wyc.util.wycbuildtask.setverificationconditions(boolean)                    wycbuildtask.java:359 | void wyc.util.wycbuildtask.setwhileydir(file)                   directoryroot.java:135 | directoryroot.folder wyfs.util.directoryroot.root()                   directoryroot.java:135 | directoryroot.folder wyfs.util.directoryroot.root()                    wycbuildtask.java:399 | void wyc.util.wycbuildtask.setbootpath(list)                                      ... | ... 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -