`
datou
  • 浏览: 3562 次
  • 来自: ...
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Utilizing ANT to Run Test Case

阅读更多
Dear All:
 While  utilizing Junit  task  to run TestCase in ANT , occur  following  error , The Test Cases  work  fine  While   running in Eclipse as Junit Test .
Below  are  error  trace  and   Ant  task code:

error trace:

quote:

 

java 代码
 
  1. jtest:  
  2.     [junit] Running com.reyes.business.DefaultBookingServiceTest  
  3.     [junit] Testsuite: com.reyes.business.DefaultBookingServiceTest  
  4.     [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec  
  5.     [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec  
  6.     [junit] Null Test:     Caused an ERROR  
  7.     [junit] com.reyes.business.DefaultBookingServiceTest  
  8.     [junit] java.lang.ClassNotFoundException: com.reyes.business.DefaultBookingServiceTest  
  9.     [junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)  
  10.     [junit] at java.security.AccessController.doPrivileged(Native Method)  
  11.     [junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)  
  12.     [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)  
  13.     [junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)  
  14.     [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)  
  15.     [junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)  
  16.     [junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)  
  17.     [junit] at java.lang.Class.forName0(Native Method)  
  18.     [junit] at java.lang.Class.forName(Class.java:247)  
  19.     [junit] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)  
  20.     [junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)  
  21.     [junit] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)  
  22.     [junit] Test com.reyes.business.DefaultBookingServiceTest FAILED  



ANT  target  code:

quote:

xml 代码
 
  1. <!---->-- =================================  
  2.       target: jtest               
  3.      ================================= -->  
  4. <target name="jtest" depends="compile" description="--> description">  
  5.     <junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed" showoutput="true">  
  6.         <classpath refid="master-classpath" />  
  7.         <formatter type="brief" usefile="false" />  
  8.         <batchtest>  
  9.             <fileset dir="${build.dir}">  
  10.                 <include name="**/*Test.*" />  
  11.             <!---->fileset>  
  12.         <!---->batchtest>            
  13.     <!---->junit>  
  14. <!---->target>   



Thank  you  for anyone give me help or where to find the solution
分享到:
评论
1 楼 datou 2007-04-22  
i found solution at website:http://ant.apache.org/faq.html#delegating-classloader

Find below paragraph:


<style> or <junit> ignores my <classpath>

Starting with Ant 1.7.0, <junit> will honor your nested <classpath>.

These tasks don't ignore your classpath setting, you are facing a common problem with delegating classloaders.

This question collects a common type of problem: A task needs an external library and it has a nested classpath element so that you can point it to this external library, but that doesn't work unless you put the external library into the CLASSPATH or place it in ANT_HOME/lib.

Some background is necessary before we can discuss solutions for Ant 1.5.x and Ant 1.6.x.

When you specify a nested <classpath> in Ant, Ant creates a new class loader that uses the path you have specified. It then tries to load additional classes from this classloader.

In most cases - for example using <style> or <junit> - Ant doesn't load the external library directly, it is the loaded class that does so.

In the case of <junit> it is the task implementation itself and in the case of <style> it is the implementation of the org.apache.tools.ant.taskdefs.XSLTLiaison class.

As of Ant 1.7 <junit> no longer requires you to have junit.jar in Ant's startup classpath even if ant-junit.jar is present there.

Ant's class loader implementation uses Java's delegation model, see http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html the paragraph

    The ClassLoader class uses a delegation model to search for classes and resources. Each instance of ClassLoader has an associated parent class loader. When called upon to find a class or resource, a ClassLoader instance will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself. The virtual machine's built-in class loader, called the bootstrap class loader, does not itself have a parent but may serve as the parent of a ClassLoader instance.

The possible solutions depend on the version of Ant you use, see the next sections.


then i modified my junit task code

<junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
			<!--<classpath refid="master-classpath" />-->
			<classpath >
			    <pathelement location="${build.dir}"/>
				<path>
					<fileset dir="${lib.dir}">
								<include name="*.jar" />
							</fileset>
				</path>
			  </classpath>
			<formatter type="brief" usefile="false" />
			<batchtest >
				<fileset dir="${build.dir}">
					<include name="**/*Test.*" />
				</fileset>
			</batchtest>
			
		</junit>


after that junit runing in ant is successful!

相关推荐

Global site tag (gtag.js) - Google Analytics