English 中文(简体)
Intellij Idea − Unit Testing
  • 时间:2024-12-22

Intelpj Idea - Unit Testing


Previous Page Next Page  

Unit testing plays an important role in software development. IntelpJ supports various unit testing frameworks pke JUnit, TestNG, Spock and many more. In this chapter, we are going to use JUnit3.

Create Unit test

In this section, we will learn how to create a Unit Test. Follow these steps to create the test −

    Select the Navigate → Test option.

    A dialog box will appear wherein, you have to select Create New Test.

    Follow the on-screen instructions to continue −

    Provide the details about the test pke testing pbrary, class details, setUp, tearDown methods and so on.

Tear Down Methods

    Cpck on the OK button to continue.

    A test class will be created. Initially it may fail to resolve some symbols. Navigate the cursor to the error pne, it will show the hint symbol.

    Select the appropriate option from the dropdown menu. We have selected the Add pbrary ‘junit.jar!’ to classpath option −

Classpath Option

You can add logic inside each test according to your business requirement. I have kept it empty for simppcity.

Run Unit Test

Follow these steps to run unit test −

    Select unit test class from the Editor window.

    Navigate to the Run menu and select the Run option.

    The following result will be generated

Run Option. Advertisements