Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Kenneth Milota
PLUS
Kenneth Milota
Courses Plus Student 178 Points

Why doesn't the assertEquals(String, String); method work on Netbeans?

Just so you know, I hate Netbeans. I think it is a far inferior IDE to Eclipse, but for some reason our professors require turning in projects through Netbeans. However, the JUnit test cases don't work on Netbeans, only Eclipse that I need to test for my current project.

I made an Animal class, and in this case, I am testing it......

           import static org.junit.Assert.*;

             import org.junit.Test;

          public class AnimalTest {

      @Test
      public void testAnimalMovement() {
      Animal animal1= new Animal();
       String x=animal1.movement(false);
       assertEquals("I walk on four legs", x);

This test works just fine on Eclipse, but the assertEquals is giving me the cannot find symbol error on Netbeans. Why would the test be valid on one IDE, but not another?

2 Answers

Kenneth Milota
PLUS
Kenneth Milota
Courses Plus Student 178 Points

It turns out the reason it didn't work is because it wasn't in the right package. NetBeans uses a different system where the test cases are in separate folders, but a new package has to be created where the name matches the package where all the classes of the project are kept.

The code:

           import static org.junit.Assert.*;

             import org.junit.Test;

is bringing in code from a Jar -compiled java code aka java library

You need to import the junit jars for both eclipse and netbeans, somehow you got lucky and eclipse imported it for you which isn't normal but is possible.

Download this jar: https://sourceforge.net/projects/junit/files/latest/download

Then this instruction for Netbeans I think should work: http://oopbook.com/java-classpath-2/classpath-in-netbeans/

You may also need hamcrest jar but if you google this one and add it the same way of the other jar