gradle icon indicating copy to clipboard operation
gradle copied to clipboard

Incorrect deprecation warning when a project contains only disabled template tests

Open ghale opened this issue 1 year ago • 1 comments

Current Behavior

When a project contains only disabled JUnit5 template tests, these tests are not reported to Gradle with "skipped" events. To Gradle, it appears as if no tests were found/executed at all (instead of tests found, but skipped) and it generates a deprecation warning:

No test executed. This behavior has been deprecated. This will fail with an error in Gradle 9.0. There are test sources present but no test was executed. Please check your test configuration. Consult the upgrading guide for further information: https://docs.gradle.org/8.11-20240826040000+0000/userguide/upgrading_version_8.html#test_task_fail_on_no_test_executed

Expected Behavior

No deprecation warning should be generated. This deprecation is intended to catch cases where someone has misconfigured their test task somehow (i.e. junit5 sources, but junit4 test framework configured). In this case, there are tests, the correct framework is used, but all tests are disabled.

Context (optional)

This was noticed in the spring-boot build: https://ge.spring.io/s/wimvsywgo7uh4/deprecations#37. They have tests that are disabled when docker is unavailable. Some of their projects have only template tests, so when docker is unavailable, they get this deprecation.

Steps to Reproduce

Add only a disabled template test, for example:

import org.junit.jupiter.api.extension.*;
import org.junit.jupiter.api.*;
import java.util.stream.Stream;
import java.util.List;
import java.util.Collections;

public class SomeTest {
    @TestTemplate
    @ExtendWith(CustomTemplateInvocationContextProvider.class)
    @Disabled
    public void templateTest() { }

    static public class CustomTemplateInvocationContextProvider implements TestTemplateInvocationContextProvider {
        public CustomTemplateInvocationContextProvider() { }

        @Override
        public boolean supportsTestTemplate(ExtensionContext context) {
            return true;
        }

        @Override
        public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
                ExtensionContext context) {
            return Stream.of(invocationContext("foo"), invocationContext("bar"));
        }

        private TestTemplateInvocationContext invocationContext(String parameter) {
            return new TestTemplateInvocationContext() {
                @Override
                public String getDisplayName(int invocationIndex) {
                    return parameter;
                }

                @Override
                public List<Extension> getAdditionalExtensions() {
                    return Collections.singletonList(new ParameterResolver() {
                        @Override
                        public boolean supportsParameter(ParameterContext parameterContext,
                                ExtensionContext extensionContext) {
                            return parameterContext.getParameter().getType().equals(String.class);
                        }

                        @Override
                        public Object resolveParameter(ParameterContext parameterContext,
                                ExtensionContext extensionContext) {
                            return parameter;
                        }
                    });
                }
            };
        }
    }
}

Configure the test task to use junit jupiter and run the test task. The deprecation will be generated.

Gradle version

8.10

Build scan URL (optional)

https://ge.spring.io/s/wimvsywgo7uh4/deprecations#37

Your Environment (optional)

No response

ghale avatar Aug 26 '24 14:08 ghale

maybe related #29895

big-guy avatar Aug 26 '24 16:08 big-guy