I have a project that uses JUnit for unit tests. The problem is that when I try to compile and run my project from Eclipse, everything works excellent, but when I try to compile with Ant, I get tons of errors that it does not recognize any function from JUnit (like test()). I copied junit.jar inside the project folder, my classpath is “./”, but it still does not work. Anybody has an idea of what I should do to get this done?
I have a project that uses JUnit for unit tests. The problem is that
Share
You need to make sure the JUnit jar is in your classpath when you compile your test code. You’ll also need all the other dependencies, plus your classpath for the classes you previously compiled.
Say this is how you compiled your regular code:
Notice I have my a directory that contains all the jars that my code is dependent upon. This is
${main.lib.dir}. Notice that my classes are compiled to the${main.destdir}. Also notice I have a property pointing to the actual JUnit jar in${junit.jar}. I don’t use that one just yet.Now to compile my test classes:
Notice that there are now three items in my classpath:
After you compile your test claasses, you can now use the
<junit>task to run your tests: