Creating Tests With JUnit.About Blog Projects
JUnit is a fantastic framework for applying unit tests to your project. It is simple to use and capable of creating large-scale, complex test classes. If you are not familiar with unit tests, or any form of testing for that matter, please refer to my blog post.
For a complete list of methods please refer here. As you can see, there are many to choose from, all basically being variations of comparable operators. You can pass almost any data type you like and JUnit will do all the hard work for you, all you have to do is determine the expected result. There's not much else'
JUnit and Eclipse
Probably the easiest way to implement a JUnit test is to use an IDE such as Eclipse or Netbeans, because it is already built in. Once you have created your project, simply select a new JUnit class from the menu (file->new->JUnit Test Case). If it is not in the list, try selecting "other" in the dropdown. If you are using Netbeans, you may find it in the "Unit Test" category. Once the file is created and your statements are added, right-click the JUnit class and select "Run As JUnit Test".
Junit Test Example
If you need an example to help you start, feel free to download this one. It is a simple project imitating a StringBuffer, which is then tested for functions such as "append()" and "charAt()". If you have any questions, please leave them using the comments form below.