Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

How to run test cases in a jar file using junit?

Thread view: 
webzhao - 13 Dec 2007 10:05 GMT
I want to run test cases in a jar file using junit and the jar file is
not in the class path. I wrote the following code, but it does not
work.

import java.net.URL;
import java.net.URLClassLoader;
import junit.framework.TestResult;
import junit.textui.TestRunner;
public class MyTestRunner {
    public static void main(String[] args) throws Exception{
        URL url = new URL("file:///d:/case.jar");
        URLClassLoader loader = new URLClassLoader(new URL[]{url});
        loader.loadClass("TestCase1");
        TestRunner runner = new TestRunner();
        TestResult result = runner.start(new String[]{"TestCase1"});
        System.out.println(result.toString());
    }
}

any ideas?

Thanks a lot.
proudbug - 13 Dec 2007 15:43 GMT
> I want to run test cases in a jar file using junit and the jar file is
> not in the class path. I wrote the following code, but it does not
[quoted text clipped - 19 lines]
>
> Thanks a lot.

what's the error message?
webzhao - 14 Dec 2007 08:57 GMT
Class TestCase1 not found.

I am developing a tool which reads test cases in a jar file and uses
junit to run these cases.

> > I want to run test cases in a jar file using junit and the jar file is
> > not in the class path. I wrote the following code, but it does not
[quoted text clipped - 21 lines]
>
> what's the error message?
proudbug - 14 Dec 2007 14:35 GMT
> Class TestCase1 not found.
>
> I am developing a tool which reads test cases in a jar file and uses
> junit to run these cases.

The code works on my machine. I think there's something wrong with the
classpath. Double check the url to see if case.jar is where you claim.
Also check if TestCase1 class is in any package. e.g. if TestCase1 is
in package comp.lang.java and under the folder comp/lang/java/ of
case.jar root, then you need to write:
    loader.loadClass("comp.lang.java.TestCase1");

> > > I want to run test cases in a jar file using junit and the jar file is
> > > not in the class path. I wrote the following code, but it does not
[quoted text clipped - 23 lines]
>
> - Show quoted text -


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.