A simple Junit question

Posted on 2005-04-20
Last Modified: 2010-03-31

I sit in front of my pc and a don't come further.... Can anyone tell me, where is the error is. There is the code

import junit.framework.*;

public class AdressListeTest extends TestCase {

      public void testaddAlbum() {
            AdressListe ab = new AdressListe();
            assertTrue(ab.add("Name", "Firstname", "Adress", "Postcode", "town", "phonenumber"));

      public void testload() {
            AdressListe a = new AdressListe();
            a.add("Name", "Firstname", "Adress", "Postcode", "town", "phonenumber");
      public void testsave() {
            AdressListe a = new AdressListe();
            a.add("Name", "Firstname", "Adress", "Postcode", "town", "phonenumber");
      public static void main(String[] args) {



I can compile the programm without problems.
Ohhh in the background is a small adressbook, whitch handles the Adresses and this should only be a Junit Test. I have the same problems, i use the swingui instead of the textui, from Junit. And here comes the errorcode from netbeans (4.0 and JDK 1.5). Off course, i have compiled all files, before i have tried to run the AdressListeTest.


Compiling 1 source file to D:\Java\Adressbook\Application\build\classes
java.lang.NoClassDefFoundError: application/AdressListeTest (wrong name: AdressListeTest)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClassInternal(
Exception in thread "main"
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Question by:mystixs
    LVL 15

    Expert Comment

    It seems that your class AdressListeTest does not have package declaration but when you are running junit you are specifying application.AdressListeTest
    remove the application from the classname to run.

    Author Comment

    Yesterday was running the program. Without package names and i have 3 classes, and

    How should i insert the package names???  Wehn i hav inserted at all files "package adress;", it hasn't run. I have got only a lot of error messages from the coompiler.  

    It can't be so hard ;-)
    LVL 15

    Expert Comment

    >> It can't be so hard ;-)
    Right, you can either add the package declarion to your classes or change the way you run your junit to run AdressListeTest instead of application.AdressListeTest.
    Did you try the latter?

    Author Comment

    It doesn't work. I have renamed the testclass and the result is the same. Do you have any other idea? I get always the same error message.
    LVL 15

    Accepted Solution

    I didn't suggest to rename the testclass.
    I suggested to change the way you are invoking the test class.
    If you are using your IDE then I am sure you can specify which test class to run (then make sure it is AdressListeTest and not application.AdressListeTest).
    This suggest you are doing it thru a build.xml (so this is probaby where you want to change it).

    Author Comment

    Thanks for your help!!!!

    My program is running now. I don't know why, but it runs. I have remove all Javacomponents and Netbeans, after that i have restarted my pc and have downloaded the new JDK and have installed the new JDK and Junit. After that i have tried to compile and run the program an what a suprise it runs!!!!

    Windows isn't ever the best choice......


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    userCompare  challenge 3 55
    commonTwo  challenge 63 69
    countX 22 53
    wordmultiple challenge 12 66
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now