Skip to content

Commit

Permalink
Integration test task does depend now on cleanIntegrationTest #3829
Browse files Browse the repository at this point in the history
- integration tests now depend on cleanIntegrationTest task
  to remove old junit results (skipped results are still results
  for gradle and new output does not appear /is collected...)
  • Loading branch information
de-jcup committed Jan 31, 2025
1 parent 56dd7c8 commit 495d6be
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
26 changes: 21 additions & 5 deletions sechub-integrationtest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,18 @@ task stopIntegrationTestInstances(dependsOn: [stopIntegrationTestServer, stopInt

}

task cleanIntegrationTest(type: Delete) {
delete "${project.buildDir}/test-results", "${project.buildDir}/reports/tests", "${project.buildDir}/sechub-testreports"
}

/**
* Own task for integration tests.
* We use cleanIntegrationTest task as dependency here - reason: When tests are executed before in CI/CD, the integration
* tests are skipped - which is okay. Unfortunately gradle will assume that there are no changes in tests
* (source has not changed, test was executed, so means still valid...). To avoid this we do the cleanTest
*/
task integrationtest(type: Test, dependsOn: startIntegrationTestInstances) {
task integrationtest(type: Test, dependsOn: [cleanIntegrationTest, startIntegrationTestInstances]) {
group 'sechub'
description 'Starts integration test server, execute tests and automatically stops server after done or failed'
// integration tests seems to be very often "up-to-date"
Expand All @@ -185,10 +192,19 @@ task integrationtest(type: Test, dependsOn: startIntegrationTestInstances) {
systemProperty "sechub.integrationtest.running", "true"

finalizedBy "stopIntegrationTestInstances"

filter {
includeTestsMatching "*IntTest"
}

/*
* we do NOT something like
* ```
* filter {
* includeTestsMatching "*IntTest"
* }
* ```
*
* Why? Because we need the cleanIntegrationTest task run (see documentation on top of task for reasons) and this
* will also cleanup the "normal" unit test results inside the gradle sub module "sechub-integration".
* Means if we would filter here, the tests would no longer exist.
*/

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import org.opentest4j.TestAbortedException;

import com.mercedesbenz.sechub.integrationtest.internal.TestScenario;

Expand All @@ -18,9 +19,13 @@ public class IntegrationTestExtension implements InvocationInterceptor {
public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
if (!IntegrationTestSupport.isIntegrationTestingEnabled()) {
String message = "Integration test skipped because not enabled. To enable please define -D" + IntegrationTestSupport.SECHUB_INTEGRATIONTEST_RUNNING

invocation.skip();

String message = "Integration test aborted because not enabled. To enable please define -D" + IntegrationTestSupport.SECHUB_INTEGRATIONTEST_RUNNING
+ "=true to enable integration tests!";
Assumptions.abort(message);

throw new TestAbortedException(message);
}

IntegrationTestSupport integrationTestSupport = null;
Expand Down Expand Up @@ -48,34 +53,34 @@ public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocatio
@Override
public void interceptAfterAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
if (!IntegrationTestSupport.isIntegrationTestingEnabled()) {
invocation.skip();
}

proceedOrSkipInvocationDependingIntegrationTestsAreEnabled(invocation);
}

@Override
public void interceptAfterEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
if (!IntegrationTestSupport.isIntegrationTestingEnabled()) {
invocation.skip();
}
proceedOrSkipInvocationDependingIntegrationTestsAreEnabled(invocation);
}

@Override
public void interceptBeforeAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
if (!IntegrationTestSupport.isIntegrationTestingEnabled()) {
invocation.skip();
}
proceedOrSkipInvocationDependingIntegrationTestsAreEnabled(invocation);
}

@Override
public void interceptBeforeEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
throws Throwable {
if (!IntegrationTestSupport.isIntegrationTestingEnabled()) {
proceedOrSkipInvocationDependingIntegrationTestsAreEnabled(invocation);
}

private void proceedOrSkipInvocationDependingIntegrationTestsAreEnabled(Invocation<Void> invocation) throws Throwable {
if (IntegrationTestSupport.isIntegrationTestingEnabled()) {
invocation.proceed();
}else {
invocation.skip();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* testing templates here, can only check common parts - e.g. info that template
* exists but is not assigned to any project.
*/
class TemplateScenario1IntTest {
public class TemplateScenario1IntTest {

private String templateId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* template check because the product (PDS) is supporting templates and the scan
* type (Web scan) is supported as well!
*/
class TemplateScenario9IntTest {
public class TemplateScenario9IntTest {

private String templateId;

Expand Down

0 comments on commit 495d6be

Please sign in to comment.