The purpose of this blog is to be seen in the title. This is what we need to experiment, we must summarize, to facilitate the other younger sister on this basis to do experiments.
I've introduced a lot of kieker-based monitoring methods, and here's an example of Prefuse, an open-source visual Java framework, that summarizes how junit and ant can monitor the running process of the open source software's own test case.
In this link, select the latest version number to download (Prefuse has not been updated for some years. Just this framework is really good).
After decompression, open its build.xml with Eclipse and discover the build.xml structure of the project is more exotic. Assuming that you execute ant all, you can generate all of your class files and jar packages (and simply solve the problem with character sets). Take a closer look and discover that you have actually compiled all the code. But there is no target in build.xml about the test. We noticed that there was a test directory after the decompression. It does have some test examples. For example here: Prefuse-beta\test\test\prefuse All_prefuse_tests.java, opened after the See: Import junit.framework.Test; Note Using JUnit 3, find a JUnit 3 jar package and put it under the Lib folder. Then we are able to compile these test classes ourselves.
First, we add a target in the Build.xml file ourselves (you need to create a TestCase folder in the build folder accordingly):
<target name= "Compile-testcase" > <javac classpath= "Lib/junit.jar:build/prefuse.jar:build/demos.jar" srcdir= "Test" destdir= "Build/testcase"/></target>
The detailed configuration of this target is very easy and I will not introduce it. Let's talk about how to use Kieker to monitor the operation of these test examples. First, likeThis blog"Aspectjweaver-1.6.11.jar" and "Commons-logging-1.1.1.jar" under "Kieker-1.4″" under "Dist" directory "Kieker-1.4.jar" and "Lib" Three jar packages are copied into the "Lib" directory in the extracted directory. We'll say a little later. The location of the Meta-inf directory.
To implement monitoring in fact very easy, we create a new target, the name casually:
<target name= "test2" depends= "Compile-testcase" > <junit printsummary= "yes" errorproperty= " test.failed " failureproperty=" test.failed " fork=" true " haltonfailure=" yes "> <formatter Type= "plain"/> <jvmarg value= "-xx:-usesplitverifier"/> <classpath path= "lib/junit.jar:lib/ Commons-logging-1.1.1.jar:lib/kieker-1.4.jar:build/testcase:build/prefuse/classes:build/demos/classes "/> <jvmarg value= "-javaagent:lib\aspectjweaver-1.6.11.jar"/> <test todir= "Test-results" Name= " Test.prefuse.All_Prefuse_Tests "/> </junit> <fail message=" Tests failed! "if=" test.failed "/ ></target>
Here are some details I will not talk about, in fact, are very easy.
In short, it is done with the jar package of Aspectjweaver javaagent, and then in Classpath includes the Kieker jar package, as well as the test class and the Test class. The reason why-xx:-usesplitverifier is used here can be seen
p=406 "style=" border:0px; Font-family:inherit; Font-style:inherit; Font-weight:inherit; margin:0px; outline:0px; padding:0px; Vertical-align:baseline; Color:rgb (25,130,209); Text-decoration:none "> This blog.
It should be pointed out that the Meta-inf directory mentioned in the previous log, simply put, in the classpath can be. So the fact that we put it in the Build/demos/classes directory (because it was already included in the classpath in the above target), the question is, can we put it in the Build.xml directory? The answer is to be able. Place it in the root directory after decompression. Then create a test-results directory (and this corresponding: <test todir= "Test-results"), the implementation of Ant Test2, you can see the results of the trial example of the execution. We were able to see that a 34 test example was executed, with one fail. It is also possible to see the generated monitoring data at the same time.
Finally, summarize the problem of Meta-inf. Practice proves: In Windows systems. When you run Java class based on ant, you are actively adding classpath to the folder where the Build.xml folder is located, but assuming that you have a Java command line, you need to add "." To increase the current folder.
But. I tested it again. Results under Mac OS X found that the "." must be added. To add the current folder, in addition, the forward and backward slashes of paths in Windows can be in ant. But in Mac OS x we can only use the backslash "/". This is a small digression, conclusion.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Using the Kieker (AspectJ) Monitoring method based on the junit and ant test programs that are running