To use JUnit in your Maven build, add the following dependency to your pom file. It is always a good idea to check for the most recent version of the dependency available in the Maven repository. In this video, we create a new maven project in NetBeans. We keep it simple and make a program that displays a greeting.
- [Teacher] To use JUnit in a Maven-built project,…you very simply need to update the POM file…to add the dependency to the JUnit framework.…And, if you're using the Hamcrest framework…to that one as well.…I think the best way to show this one…is to actually create a project in NetBeans,…using Maven, and then go ahead an add a JUnit test.…So let's go ahead and do that now.…We're gonna start by creating a new project in NetBeans.…File, New Project.…
We're going to use Maven,…but it's going to be a Java Application,…and we'll click Next.…We're going to give it a name.…Let's call it Maven example,…and I'm going to click Finish.…Now, if I open up the source packages under Maven,…we don't have any classes created yet,…so let's go ahead and right-click…and create a new class.…Let's simply call this one Helloworld.…At the bottom, I'm just gonna close my output window…and my test results,…since they don't apply to this new project.…
And I'm gonna click on the NetBeansExample,…which was what I used before.…I'm gonna right-click and say Close.…
- What is JUnit?
- Comparing values with assertions
- Using JUnit with different Java IDEs
- Creating basic unit tests
- Testing for exception handling
- Creating parameterized tests