intellij-ideajunitspock

Specify multiple test methods to run in IntelliJ IDEA


Is it possible in IntelliJ to run just some specific test methods within a test suite (JUnit or Spock)? I tried to solve that with test kind 'patterns', but it seems to me that it only filters on class level.


Solution

  • If you want to filter a specific method in the com.example.project.test.tryTest class, you can use the following syntax:

    com.example.project.test.tryTest,methodName
    

    In this case, you are filtering for the methodName in the tryTest class. It's crucial to note that you need to separate the method name from the class name with a comma (,).

    Additionally, in newer versions, you can use the || operator to add multiple tests. For example:

    com.example.project.test.tryTest,methodName1||com.example.project.test.tryTest,methodName2
    

    In previous versions, you can transition to subsequent lines to specify multiple patterns. For instance:

    com.example.project.test.tryTest,methodName1
    com.example.project.test.tryTest,methodName2
    

    This way, you can specify multiple tests in a single expression. Therefore, you filter the methods methodName1 and methodName2 in the tryTest class in this manner.

    I hope these explanations are helpful. Feel free to ask if you have any more questions.