gradle error with testng: Execution failed for task ‘:app:test’

Solution for gradle error with testng: Execution failed for task ‘:app:test’
is Given Below:

Why did execution fail?

So far as I can tell, everything builds correctly and the main class runs. Seemingly, no compile problems.

How are all tests for this class executed?

The result of the test is immaterial to the question.

using gradle:

[email protected]:~/NetBeansProjects/testng_gradle/app$ 
[email protected]:~/NetBeansProjects/testng_gradle/app$ gradle clean test --tests testing_gradle.AppTest
> Task :app:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:test'.
> No tests found for given includes: [testing_gradle.AppTest](--tests filter)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 771ms
4 actionable tasks: 4 executed
[email protected]:~/NetBeansProjects/testng_gradle/app$ 
[email protected]:~/NetBeansProjects/testng_gradle/app$ gradle clean

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 663ms
1 actionable task: 1 executed
[email protected]:~/NetBeansProjects/testng_gradle/app$ 
[email protected]:~/NetBeansProjects/testng_gradle/app$ tree
.
├── build.gradle
└── src
    ├── main
    │   ├── java
    │   │   └── testng_gradle
    │   │       └── App.java
    │   └── resources
    └── test
        ├── java
        │   └── testng_gradle
        │       └── AppTest.java
        └── resources

9 directories, 3 files
[email protected]:~/NetBeansProjects/testng_gradle/app$ 
[email protected]:~/NetBeansProjects/testng_gradle/app$ cat build.gradle 
/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java application project to get you started.
 * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
 * User Manual available at https://docs.gradle.org/7.0.2/userguide/building_java_projects.html
 */

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
    mavenLocal()
    jcenter()
}

dependencies {
    // Use TestNG framework, also requires calling test.useTestNG() below
    //compile 'org.testng:testng:7.3.0'
    testImplementation 'org.testng:testng:7.3.0'

    // This dependency is used by the application.
    implementation 'com.google.guava:guava:30.0-jre'
}

application {
    // Define the main class for the application.
    mainClass="testng_gradle.App"
}




tasks.named('test') {
    useTestNG() {
        includeGroups 'smoke', 'sanity'
        excludeGroups 'regression'
        testLogging.showStandardStreams = true
    suiteXmlBuilder().suite(name: 'Sample Suite') {
            test(name : 'Sample Test') {
                classes('') {
            'class'(name: 'testing_gradle.AppTest')
                }
            }
    }

    }
}




[email protected]:~/NetBeansProjects/testng_gradle/app$ 
[email protected]:~/NetBeansProjects/testng_gradle/app$ cat src/test/java/testng_gradle/AppTest.java 
/*
 * This Java source file was generated by the Gradle 'init' task.
 */
package testng_gradle;

import org.testng.annotations.*;
import static org.testng.Assert.*;

public class AppTest {
    @Test public void appHasAGreeting() {
        App classUnderTest = new App();
        assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
    }
}
[email protected]:~/NetBeansProjects/testng_gradle/app$ 

presumably the build.gradle for this example is flawed.