Methods for monitoring using Kieker (AspectJ) for JUnit and Ant-based test case execution procedures

Source: Internet
Author: User

The purpose of this blog is to be seen in the title. This is also our experimental needs, 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 enable monitoring of the open source software's own test case execution process. In this link, choose the latest version of the download (Prefuse has not been updated for some years, but the framework is really good).

After decompression opened its build.xml with Eclipse, found that the build.xml structure of the project is still more wonderful. If you run 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 find that you actually compiled all the code, but there's no target in build.xml for testing. We noticed that there was a test folder after the decompression, and there were some testing cases. 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 in the Lib directory. Then we can compile these test classes on our own.

First, we add a target in the Build.xml file ourselves (we need to create a TestCase folder in the build directory):

<target name= "Compile-testcase" > <javac classpath= "Lib/junit.jar:build/prefuse.jar:build/demos.jar" srcdir= "Test" destdir= "Build/testcase"/></target>

The specific configuration of this target is very simple and I will not introduce it. Let's talk about how to monitor the execution of these test cases with kieker. First, likeThis blogin this way: "Kieker-1.4″" under "Dist" folder "Kieker-1.4.jar" and "Lib" under the folder "Aspectjweaver-1.6.11.jar" and " Commons-logging-1.1.1.jar "Three jar packages are copied into the" Lib "folder in the extracted directory. We'll say a little later. Meta-inf folder location. To implement the monitoring is actually very simple, 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 simple. To put it simply, aspectjweaver the jar package as a javaagent and then include the Kieker jar package in Classpath, as well as the test class and the tested class. -xx:-usesplitverifier the reasons for use here can be see this log. It should be pointed out that the previous log mentioned in the Meta-inf folder, simply speaking, put in the classpath can be, so we actually put in build/demos/ Classes such a folder (because it has been included in the target in the classpath), the question is, can we put it under the Build.xml folder? The answer is yes. Put it in the root directory after decompression, and then create a Test-results folder (and this corresponds to: <test todir= "Test-results"), run ant test2, you can see the results of the test case run. As we can see, we run 34 test cases, one of which is fail, and we can see that the monitoring data is generated.

Finally, summarize the problem of Meta-inf. It is proven that in Windows systems, when you execute Java class based on Ant, the directory where the Build.xml directory is located is automatically added to the classpath, but if you go through the Java command line, you need to add "." To join the current directory.

However, I tested the results under Mac OS X and found that I had to add "." To join the current directory, in addition, the forward and backward slashes of paths in windows are available in ant, but only the backslash "/" can be used in Mac OS x. This is a little off-topic, to summarize.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.