JUnit is a Java library designed to help you perform this unit testing. Unit testing is the process of examining a small "unit" or piece of software to verify that it meets the business rules provided. The goal is to assert the expected behavior or state. It is important to understand that JUnit is not part of the standard Java class libraries, but it does come included with some of the popular IDEs.
- [Instructor] You might be wondering what is JUnit? Let's start by talking about how to test a program. When a programmer is given an assignment to write a Java program, they are usually given a set of business rules as well as sample input and expected output. All this information is used by the programmer to write the program. Then, when the coding is done, it is used as a guide to test the application. That's where JUnit comes into play. JUnit is a Java library designed to help you perform this unit testing.
Unit testing is the process of examining a small unit, or piece, of software to verify that it meets the business rules provided. The goal is to assert the expected behavior or state. It is important to understand that JUnit is not part of the standard Java class library. But it does come included with some of the popular IDEs. As I'm sure you're aware, there are many ways to test your code. Including using the IDE debugging tool.
Or simply adding some print statements to print the results to the output console. These options are great when you're working on your code and trying to debug any logic errors. But both styles of test are limited because they require human judgment to analyze their results. So in addition to the debugging tools mentioned, and print statements, we needed a way to continue unit testing. This is where JUnit comes in handy. It provides automated testing and validation.
Remember, good unit testing is critical to the success of your application. Have you ever had a game where you were playing crash right as you were getting ready to battle the bad guy? Or when visiting a website, you receive a HTTP 404 Message Page Not Found. These types of problems cause the end user to lose confidence in your application. So you want to make sure that your thoroughly test every possible scenario. This can be time consuming, but using JUnit, you can run several tests with one execution.
When testing, we need to identify any inputs to methods in our code as well as expected results. It is important to note that once all unit testing is complete, you still need to run integration tests for any applications that have complex user interfaces or other component interaction. An integration test aims to test the behavior of a component or the integration between multiple components. These tests are used to test the entire system.
Finally, another type of testing is performance testing. These tests are used to benchmark the software by running repeatedly to simulate user traffic on your application. The purpose is to ensure the code runs fast enough under a high traffic load. JUnit not set up to do integration or performance testing, but it will help you get your unit testing done completely and efficiently.
- What is JUnit?
- Comparing values with assertions
- Using JUnit with different Java IDEs
- Creating basic unit tests
- Testing for exception handling
- Creating parameterized tests