Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No tests found for given includes after upgrade to Gradle 5.1.1

Tags:

gradle

testng

We used to have a few commands like following:

gradlew test --tests *MyTest

For example the class MyTest is in the package com.test.MyTest. When using a Gradle version < 5.0 this worked just fine but after the upgrade to 5.1.1 I get following error:

No tests found for given includes: [*MyTest](--tests filter)

We have already replaced all such occurrences because I think using the full path to a class is much better. But I am wondering why this isn't working anymore.

BTW: I am using TestNG and the mentioned class has at least one public method annotated with @Test.

like image 214
AndiCover Avatar asked Dec 04 '22 18:12

AndiCover


2 Answers

It took me a lot of digging around to find the solution, so sharing it here. I solved the No tests found for given includes: [*MyTest](--tests filter) error by changing the Intellij settings according to https://linked2ev.github.io/devsub/2019/09/30/Intellij-junit4-gradle-issue/

Steps:

  1. File > Setting (Ctrl+Alt+S)
  2. Build, Execution, Deployment > Build Tools > gradle
  3. Run Tests using: Intellij IDEA
like image 100
Jonathan Lee Avatar answered Apr 23 '23 12:04

Jonathan Lee


Found the problem. It has nothing to do with the gradle upgrade or with TestNG.

Basically someone initialized a global variable in some other class and used an fixed index there i.e.

public class myClass extends Something{
    private final String name = names.getNames(0);
    ...

When we called the gradle task with * it executed that piece of code and in that case it lead to an IndexOutOfBoundsException because the list is empty at that point of time.

Executing following command helped me finding the problem:

gradlew test --tests *MyTest --debug
like image 32
AndiCover Avatar answered Apr 23 '23 12:04

AndiCover