IntelliJ IDEA 13.1 Web Help

The libraries for JUnit and TestNG are shipped with IntelliJ IDEA, but are not included in the classpath of your project or module by default. Consequently, when a test class is created, the references to the TestCase class or test annotations are not resolved.

To add the necessary library to the classpath, you can use the general procedure of configuring libraries. The corresponding libraries are located in the following directories:

  • JUnit libraries (junit.jar and junit-4.8.jar): <IntelliJ IDEA directory>\lib.
  • TestNG library (testng-jdk15.jar): <IntelliJ IDEA directory>\plugins\testng\lib.

IntelliJ IDEA can add the necessary library to the classpath automatically. The corresponding features are available when creating a test for a class or when writing the code for a test.

Adding a test library to the classpath when creating a test for a class
  1. In the editor, place the cursor within the line containing the class declaration.
  2. Press Alt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+Enter, Shift+Alt+J or Ctrl+Shift+MAlt EnterAlt EnterCommand 1 to view the available intention actions.
  3. Select Create Test.
  4. In the Create Test dialog, to the right of the text informing you that the corresponding library is not found, click Fix.

    fix_missing_lib.png

Adding a test library to the classpath when writing the code for a test
  1. In the source code of a test class, place the cursor within an unresolved reference to TestCase or annotation.
  2. Press Alt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+Enter, Shift+Alt+J or Ctrl+Shift+MAlt EnterAlt EnterCommand 1 to view the available intention actions.
  3. Select Add <library> to classpath.

    addJunitJar.png

See Also

Procedures:

Language and Framework-Specific Guidelines:

Reference:

Web Resources: