Meet 2025’s Top-rated Software Test Management Tool. Learn More >

How to create a JUnit test case in intellij IDEA

In this article

To create a JUnit test case in IntelliJ IDEA:

  1. Add JUnit to Your Project: If JUnit is not included, right-click your project, select Add Framework Support, and choose JUnit. Alternatively, add JUnit as a dependency in your build file (e.g., Maven or Gradle).
  2. Generate a Test Class: Right-click the class you want to test in the Project Explorer. Select Generate > Test… or press Ctrl+Shift+T (Windows/Linux) or Cmd+Shift+T (Mac). In the dialog, select JUnit 4 or JUnit 5, choose methods to test, and click OK to create the test class.
  3. Write Test Methods: Use @Test annotations for each test method. Add assertions such as assertEquals, assertTrue, or assertThrows to validate expected outcomes.
  4. Run the Test Class: Right-click the test class in the editor or Project Explorer. Select Run ‘TestClassName’ to execute all test methods. View test results in the Run window.
  5. Debug and Refine: Use the Debug option to investigate any test failures and make necessary code fixes.

How to automate JUnit test cases in Java

To automate JUnit test cases in Java:

  1. Write Test Cases: Create test classes with methods annotated with @Test to define your test logic using assertions such as assertEquals, assertTrue, etc.
  2. Organize Tests: Use JUnit features like test suites (JUnit 4: @RunWith(Suite.class), JUnit 5: @Suite) to group and manage multiple test classes for execution.
  3. Integrate with a Build Tool: Use Maven or Gradle to automate test execution as part of the build process. In Maven, include the maven-surefire-plugin to run JUnit tests automatically during the mvn test phase.
  4. Add Tests to CI/CD Pipelines: Configure continuous integration tools such as Jenkins, GitHub Actions, or Azure Pipelines to execute JUnit tests automatically during builds.
  5. Trigger Tests Programmatically: Use the JUnit platform launcher API to programmatically run tests within your Java application if needed.
  6. Generate Reports: Enable reporting tools such as Surefire Reports (Maven) or test logging frameworks to automate result analysis and reporting.
Picture of Sridhar K

Sridhar K

All Posts

Deliver quality software with QA Touch

Questions? Explore our docs, videos, and more just one click away!

Real people with life changing results

Insights from QA Teams on QA Touch’s Impact

Frequently asked questions

Everything you need to know about the product and billing

Why QA Touch?

QA Touch is an AI-driven test management platform built by testers for testers. It simplifies collaboration between developers and QA engineers while helping to manage, track, and organize test cases efficiently. Streamline your testing processes, enhance QA visibility, and deliver high-quality software with ease.

QA Touch offers comprehensive features to manage the entire test management process. From easy migration with CSV files to audio-visual recording of issues and activity logs and a shareable dashboard for real-time reporting to stakeholders, we ensure the testing teams are always on top of things.

Our focus is on providing complete visibility and control over testing workflows and fostering collaboration between testers and other stakeholders (both internal and external). You can have a look at all the features here.

Once you sign up, it takes only 30 minutes to get your QA Touch account up and running. After registration, you will receive an account activation email with all the details. Log in with your account details and create your first test project on QA Touch—it’s that simple. You are now ready to start inviting your team and assigning them roles.

If you are finding it difficult to log in or facing any difficulty, feel free to reach our support team at info@qatouch.com

Why is QA Touch the best test management tool for me?

QA Touch is an AI-driven test management platform that simplifies collaboration between your developers and testers. Beyond creating, organizing, and executing test cases, QA Touch enables you to manage projects, track bugs, and monitor time—all in one platform.

With an intuitive UI and seamless two-way integrations, QA Touch adapts to your workflow, making test management, project oversight, and bug tracking smarter and more efficient.

With secure OKTA, Microsoft Azure SSO, and Google SSO enterprise features, you can stay connected in every app.

We have integrations with dozens of major apps like Slack, Jira, Monday.com, Cypress, and many more. Explore the whole list of integrations now supported here: Explore integrations

The test management tool is a modern software application that helps QA teams and developers manage their testing process efficiently. It provides a structured approach to creating, organizing, executing, and tracking tests to ensure software applications meet specified requirements and function properly before release.

Don’t just take our word for it.

QATouch is a leader in G2 market reports.