Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit b58284a

Browse files
committed
Use junit tags with tests
- Remove "integrationTests" from build in favour of tagging tests - Only untagged tests are run by default, thought we can can modify default includeTags = ['none()'] if there's need to run some tags on default - Use -PcliIncludeTags=exp1,exp2 and/or -PcliExcludeTags=exp1,exp2 to manually define what tags to use - Also -PcliTestLogging which takes boolean and defaults to true if defined as it enables more verbose test logging - Added CliTags which should always have valid and expected tags having some defaults like; it, smoke, ai, github and gitlab - Fixes #197
1 parent 5a89f45 commit b58284a

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

build.gradle

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,36 +139,28 @@ dependencyManagement {
139139
}
140140

141141
test {
142-
useJUnitPlatform()
143-
}
142+
useJUnitPlatform {
143+
if (!project.hasProperty('cliIncludeTags') && !project.hasProperty('cliExcludeTags')) {
144+
includeTags = ['none()']
145+
}
146+
else {
147+
if (project.hasProperty('cliIncludeTags') && cliIncludeTags.size() > 0) {
148+
includeTags = cliIncludeTags.split(',')
149+
}
150+
if (project.hasProperty('cliExcludeTags') && cliExcludeTags.size() > 0) {
151+
excludeTags = cliExcludeTags.split(',')
152+
}
153+
}
144154

145-
sourceSets {
146-
integrationTest {
147-
java {
148-
compileClasspath += main.output + test.output
149-
runtimeClasspath += main.output + test.output
150-
srcDir file('src/integrationTest/java')
155+
}
156+
if (project.hasProperty('cliTestLogging') && (cliTestLogging.isEmpty() ? true : cliTestLogging.toBoolean())) {
157+
testLogging {
158+
showStandardStreams = true
159+
events = ["standardOut", "started", "passed", "failed", "skipped"]
151160
}
152-
resources.srcDir file('src/integrationTest/resources')
153161
}
154162
}
155163

156-
task integrationTest(type: Test) {
157-
useJUnitPlatform()
158-
testClassesDirs = sourceSets.integrationTest.output.classesDirs
159-
classpath = sourceSets.integrationTest.runtimeClasspath
160-
}
161-
162-
configurations {
163-
integrationTestCompile.extendsFrom testCompile
164-
integrationTestRuntime.extendsFrom testRuntime
165-
integrationTestImplementation.extendsFrom testImplementation
166-
}
167-
168-
rootProject.tasks.named("processIntegrationTestResources") {
169-
duplicatesStrategy = 'include'
170-
}
171-
172164
task generateGitProperties {
173165
doLast {
174166
try {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cli;
18+
19+
/**
20+
* JUnit tags used in tests.
21+
*/
22+
public final class CliTags {
23+
24+
private CliTags() {
25+
}
26+
27+
public static final String IT = "it";
28+
29+
public static final String SMOKE = "smoke";
30+
31+
public static final String AI = "ai";
32+
33+
public static final String GITHUB = "github";
34+
35+
public static final String GITLAB = "gitlab";
36+
37+
}

src/test/java/org/springframework/cli/git/GitSourceRepositoryServiceTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
import java.nio.file.Paths;
2222

2323
import org.apache.commons.io.file.PathUtils;
24+
import org.junit.jupiter.api.Tag;
2425
import org.junit.jupiter.api.Test;
2526
import org.junit.jupiter.api.io.TempDir;
2627

28+
import org.springframework.cli.CliTags;
2729
import org.springframework.cli.config.SpringCliUserConfig;
2830

2931
import static org.assertj.core.api.Assertions.assertThat;
@@ -35,6 +37,7 @@ public class GitSourceRepositoryServiceTests {
3537
* @param tempDir location to put contents of git repository
3638
*/
3739
@Test
40+
@Tag(CliTags.GITHUB)
3841
void testRetrieval(@TempDir Path tempDir) throws IOException {
3942
GitSourceRepositoryService urlRepositoryService = new GitSourceRepositoryService(new SpringCliUserConfig());
4043
Path contentPath = urlRepositoryService.retrieveRepositoryContents("https://github.com/rd-1-2022/rest-service");
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,10 @@
1616

1717
package org.springframework.cli.merger.ai;
1818

19+
import org.junit.jupiter.api.Tag;
1920
import org.junit.jupiter.api.Test;
2021

22+
import org.springframework.cli.CliTags;
2123
import org.springframework.cli.merger.ai.service.ProjectNameHeuristicAiService;
2224
import org.springframework.cli.util.TerminalMessage;
2325

@@ -26,6 +28,7 @@
2628
class ProjectNameHeuristicAiServiceTests {
2729

2830
@Test
31+
@Tag(CliTags.AI)
2932
void deriveProjectName() {
3033
ProjectNameHeuristicAiService projectNameHeuristic = new ProjectNameHeuristicAiService(TerminalMessage.noop());
3134

0 commit comments

Comments
 (0)