Dennis Deems wrote:Test code should be in a separate file. Tests are generally kept in a separate source folder, but while you are learning it's fine to keep them in the same package with the classes they test.
A test is just a small program that typically instantiates a class and verifies its behavior. The idea is to make the class do everything it can do - call every public method, force every execution path to occur - and make sure that what you expect to happen is what actually happens.
There's also a school of thought (to which I happen to subscribe) that says that you put your test classes in a different
directory from your "real" classes, but in the same
package, so that you can test package-private methods more easily, and also for simple ease of organization--you have x.y.z.FooTest which tests x.y.z.Foo.