Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKenneth Milota
Courses Plus Student 178 PointsWhy 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
Courses Plus Student 178 PointsIt 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.
Steven Kelsey
12,524 PointsThe 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