JUnit TutorialIntroduction to Junit JUnit Set up JUnit Architecture JUnit Annotations JUnit Fixtures Junit Assertions Junit Categories @Test Annotation Parameters Verification of Exceptions Ignoring tests Time out in JUnit tests Parameterizing tests Test Suite TestWatcher TemporaryFolder ExternalResource Theories in JUnit JUnit Test Runners Execution order of JUnit tests Assumptions in JUnit JUnit and Hamcrest Matchers Running JUnit tests in parallel JUnit and Maven Integration JUnit and Gradle Integration Executing Selenium tests using JUnit test framework Method interceptor and usage JUnit in Intellij IDEA JUnit in Eclipse
Running tests in IntelliJ IDEA in junitIn this post, I am going tell you how to write JUnit tests in Intellij IDEA. IntelliJ IDEA provides an excellent support to JUnit tests. JUnit plug-in is by default installed in IntelliJ IDEA. Writing and executing JUnit tests is very simple in IntelliJ IDEA. You need to create a simple maven or gradle project and add JUnit dependency.
Adding JUnit dependencyIf you are using Maven project, use below dependency in POM file.
If you are using Gradle project, add below lines in build.gradle file.
apply plugin: 'java'
Writing JUnit TestsWe have already seen how to write simple JUnit tests.
Executing JUnit Tests in IntelliJ IDEAWe can execute JUnit tests in Intellij IDEA by right clicking on a test class and then selecting Run option as shown in below image.You can also use Ctrl+Shift+F10 shortcut key to run current JUnit test. To run Junit tests in specific package, you can right click on that package and click on run. Similarly to run all tests in all packages, you can right click on Java directory and click on Run all tests.
Viewing the JUnit test reports in IntelliJ IDEAAfter running the JUnit tests, IntelliJ IDEA creates a beautiful HTML report. Below images show how to view JUnit HTML report generated by IntelliJ IDEA. Below image shows sample output of Junit test execution. To export the report in HTML format, click on icon highlighted in yellow color.Below image shows sample JUnit test execution report generated by Intellij IDEA.If you are using a maven project, you can also execute JUnit tests using maven commands.
Web development and Automation testing