Agile Javaв„ў: Crafting Code with Test-Driven Development
Compile the test. You should expect to see problems,[6] since you have only built the test class StudentTest. StudentTest refers to a class named Student, which is nowhere to be foundyou haven't built it yet! [6] You may see different errors, depending on your Java compiler and/or IDE. StudentTest.java:3: cannot find symbol symbol : class Student location: class StudentTest new Student("Jane Doe"); ^ 1 error
Note the position of the caret (^) beneath the statement in error. It indicates that the Java compiler doesn't know what the source text Student represents. The compile error is expected. Compilation errors are a good thingthey provide you with feedback throughout the development process. One way you can look at a compilation error is as your very first feedback after writing a test. The feedback answers the question: Have you constructed your code using proper Java syntax so that the test can execute?
To eliminate the current error, create a new class named Student.java. Edit it to contain the following code: class Student { }
Run javac again, this time using a wildcard to specify that all source files should be compiled: javac -cp c:\junit3.8.1\junit.jar *.java
You will receive a new but similar error. Again the compiler cannot find a symbol, but this time it points to the word new in the source text. Also, the compiler indicates that the symbol it's looking for is a constructor that takes a String argument. The compiler found the class Student, but now it needs to know what to do with respect to the "Jane Doe" String. StudentTest.java:3: cannot find symbol symbol : constructor Student(java.lang.String) location: class Student new Student("Jane Doe"); ^ 1 error |