Configuring IntelliJ IDEA for unit testing with JUnit

前端 未结 5 1176
刺人心
刺人心 2020-11-28 01:40

I decided to try out IntelliJ this morning via the trial version and installed the JUnit plugin. I made a new Java project and I want to write a test case for it.

Ho

5条回答
  •  甜味超标
    2020-11-28 02:33

    If you already have a test class, but missing the JUnit library dependency, please refer to Configuring Libraries for Unit Testing documentation section. Pressing Alt+Enter on the red code should give you an intention action to add the missing jar.

    However, IDEA offers much more. If you don't have a test class yet and want to create one for any of the source classes, see instructions below.

    You can use the Create Test intention action by pressing Alt+Enter while standing on the name of your class inside the editor or by using Ctrl+Shift+T keyboard shortcut.

    A dialog appears where you select what testing framework to use and press Fix button for the first time to add the required library jars to the module dependencies. You can also select methods to create the test stubs for.

    Create Test Intention

    Create Test Dialog

    You can find more details in the Testing help section of the on-line documentation.

提交回复
热议问题