A simple Junit question

Hello!!

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();
            assertFalse(a.load("test.txt"));
            a.add("Name", "Firstname", "Adress", "Postcode", "town", "phonenumber");
            a.save("test2.txt");
            assertTrue(a.load("test2.txt"));
      }
       
      public void testsave() {
            AdressListe a = new AdressListe();
            assertTrue(a.save("test3.txt"));
            a.add("Name", "Firstname", "Adress", "Postcode", "town", "phonenumber");
            assertTrue(a.save("test4.txt"));
      }
      public static void main(String[] args) {
            junit.textui.TestRunner.run(AdressListeTest.class);
      }

}

---------------------------------

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.

-----------------------------------------------

init:
deps-jar:
Compiling 1 source file to D:\Java\Adressbook\Application\build\classes
compile-single:
run-single:
java.lang.NoClassDefFoundError: application/AdressListeTest (wrong name: AdressListeTest)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
mystixsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aozarovConnect With a Mentor Commented:
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).
>> BUILD SUCCESSFUL
This suggest you are doing it thru a build.xml (so this is probaby where you want to change it).
0
 
aozarovCommented:
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.
0
 
mystixsAuthor Commented:
Yesterday was running the program. Without package names and i have 3 classes Adress.java, AdressList.java and AdressListTest.java.

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 ;-)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
aozarovCommented:
>> 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?
0
 
mystixsAuthor Commented:
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.
0
 
mystixsAuthor Commented:
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......

Thanks!!!!
0
All Courses

From novice to tech pro — start learning today.