JUnit comes integrated with Eclipse, NetBeans and IntelliJ. You can write the JUnit tests manually, but these IDEs make it much easier. This example is using the NetBeans IDE. We start by adding a new project. Next, we will walk through the steps to create a unit test using the JUnit framework. After the unit test is created, we will run it successfully and then purposely introduce an error.
- View Offline
- [Instructor] For those of you that are not familiar…with this particular integrated development environment,…this is the NetBeans IDE.…When you first open NetBeans,…you will get the start page.…If you don't want to start page to show up each time,…in the upper right hand corner,…deselect the show on startup.…I'm going to close the start page.…We're going to create a new Java application…that has a class that allows us to pass a numeric grade,…and it returns a string with the letter grade.…Then, we will use the J unit tool…that is integrated with NetBeans…to create a unit test for that class.…
Let's get started.…We're going to do file, new project,…and again, I'm going to leave it as a Java application.…I'm going to click next, and I'm going to…call this NetBeansExample, and I'm going to click finish.…In NetBeans, when you create a new Java application,…it automatically creates a file,…using the same name as the project,…and it adds the public static void main.…We're not going to actually use this file,…so I'm going to go to the package, NetBeansExample,…
- What is JUnit?
- Comparing values with assertions
- Using JUnit with different Java IDEs
- Creating basic unit tests
- Testing for exception handling
- Creating parameterized tests