Skip to content

Commit d99cc23

Browse files
authored
Merge pull request #83 from utPLSQL/feature/skipTests
Skip utPLSQL tests with `-DskipTests` and `-Dmaven.test.skip`
2 parents 2965094 + ce3b619 commit d99cc23

8 files changed

Lines changed: 263 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,24 @@ utPLSQL reports coverage per source file instead of per database object. The plu
216216

217217
## Skipping tests
218218

219-
Set `skipUtplsqlTests` to `true` in the plugin configuration or on the command line:
219+
The utPLSQL tests are skipped together with other tests by Maven's standard `-DskipTests` or `-Dmaven.test.skip=true`:
220+
221+
```bash
222+
mvn install -DskipTests
223+
```
224+
225+
To skip only the utPLSQL tests, set `skipUtplsqlTests` to `true` in the plugin configuration or on the command line:
220226

221227
```bash
222228
mvn install -DskipUtplsqlTests=true
223229
```
224230

225-
Maven's `-DskipTests` does not skip utPLSQL tests.
231+
`skipUtplsqlTests` takes precedence over `skipTests` and `maven.test.skip`. To skip other tests but run the utPLSQL
232+
tests, set it to `false`:
233+
234+
```bash
235+
mvn install -DskipTests -DskipUtplsqlTests=false
236+
```
226237

227238
To skip the tests by default and enable them only when needed, set the property in the `pom.xml`:
228239

@@ -298,9 +309,10 @@ All parameters are optional:
298309
<!-- Default: ${maven.test.failure.ignore} -->
299310
<ignoreFailure>false</ignoreFailure>
300311

301-
<!-- Skip the tests. Command line: -DskipUtplsqlTests=true -->
302-
<!-- Default: false -->
303-
<skipUtplsqlTests>false</skipUtplsqlTests>
312+
<!-- Skip (true) or run (false) the tests, regardless of skipTests and maven.test.skip. -->
313+
<!-- Command line: -DskipUtplsqlTests=true -->
314+
<!-- Default: not set, the tests are skipped by -DskipTests or -Dmaven.test.skip=true -->
315+
<!-- <skipUtplsqlTests>true</skipUtplsqlTests> -->
304316

305317
<!-- Skip the check of compatibility with the utPLSQL version in the database. -->
306318
<!-- Default: false -->
@@ -427,6 +439,10 @@ The plugin's integration tests double as examples, in
427439
* [`ora_stuck_timeout`](src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/ora_stuck_timeout):
428440
`oraStuckTimeout`.
429441
* [`skip`](src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/skip): `skipUtplsqlTests`.
442+
* [`skip_tests`](src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/skip_tests),
443+
[`maven_test_skip`](src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/maven_test_skip) and
444+
[`skip_tests_overridden_by_skip_utplsql_tests`](src/test/resources-its/org/utplsql/maven/plugin/UtPlsqlMojoIT/skip_tests_overridden_by_skip_utplsql_tests):
445+
skipping with `-DskipTests` and `-Dmaven.test.skip=true`, run with the system properties set in `UtPlsqlMojoIT`.
430446

431447
## Comparison with utPLSQL-cli
432448

‎src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,18 @@ public class UtPlsqlMojo extends AbstractMojo {
128128
@Parameter(defaultValue = "${maven.test.failure.ignore}")
129129
boolean ignoreFailure;
130130

131-
@Parameter(property = "skipUtplsqlTests", defaultValue = "false")
132-
boolean skipUtplsqlTests;
131+
/**
132+
* Skips the utPLSQL tests when true, runs them when false.
133+
* When not set, the tests are skipped together with other tests by skipTests or maven.test.skip.
134+
*/
135+
@Parameter(property = "skipUtplsqlTests")
136+
Boolean skipUtplsqlTests;
137+
138+
@Parameter(property = "skipTests", defaultValue = "false")
139+
boolean skipTests;
140+
141+
@Parameter(property = "maven.test.skip", defaultValue = "false")
142+
boolean mavenTestSkip;
133143

134144
@Parameter
135145
boolean dbmsOutput;
@@ -141,7 +151,7 @@ public class UtPlsqlMojo extends AbstractMojo {
141151

142152
@Override
143153
public void execute() throws MojoExecutionException {
144-
if (skipUtplsqlTests) {
154+
if (isSkipped()) {
145155
getLog().info("utPLSQLTests are skipped.");
146156
} else {
147157
getLog().debug("Java API Version = " + JavaApiVersionInfo.getVersion());
@@ -231,6 +241,18 @@ public void execute() throws MojoExecutionException {
231241
}
232242
}
233243

244+
/**
245+
* skipUtplsqlTests takes precedence, so -DskipTests -DskipUtplsqlTests=false skips other tests but runs utPLSQL tests.
246+
*
247+
* @return true when the utPLSQL tests should not be run
248+
*/
249+
boolean isSkipped() {
250+
if (skipUtplsqlTests != null) {
251+
return skipUtplsqlTests;
252+
}
253+
return skipTests || mavenTestSkip;
254+
}
255+
234256
private Connection createConnection() throws SQLException {
235257
if (isEmpty(url)) {
236258
url = System.getProperty("dbUrl");

‎src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoIT.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.soebes.itf.jupiter.extension.MavenGoal;
44
import com.soebes.itf.jupiter.extension.MavenJupiterExtension;
55
import com.soebes.itf.jupiter.extension.MavenTest;
6+
import com.soebes.itf.jupiter.extension.SystemProperty;
67
import com.soebes.itf.jupiter.maven.MavenExecutionResult;
78

89
import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
@@ -97,4 +98,29 @@ void include_object_expr(MavenExecutionResult result) {
9798
assertThatReportsAreGeneratedAsExpected(result, "sonar-test-report.xml", "coverage-sonar-report.xml");
9899
}
99100

101+
@MavenTest
102+
@SystemProperty(value = "skipTests", content = "true")
103+
void skip_tests(MavenExecutionResult result) {
104+
assertThat(result).isSuccessful();
105+
106+
assertThat(result.getMavenLog()).info().contains("utPLSQLTests are skipped.");
107+
}
108+
109+
@MavenTest
110+
@SystemProperty(value = "maven.test.skip", content = "true")
111+
void maven_test_skip(MavenExecutionResult result) {
112+
assertThat(result).isSuccessful();
113+
114+
assertThat(result.getMavenLog()).info().contains("utPLSQLTests are skipped.");
115+
}
116+
117+
@MavenTest
118+
@SystemProperty(value = "skipTests", content = "true")
119+
@SystemProperty(value = "skipUtplsqlTests", content = "false")
120+
void skip_tests_overridden_by_skip_utplsql_tests(MavenExecutionResult result) {
121+
assertThat(result).isSuccessful();
122+
123+
assertThat(result.getMavenLog()).info().doesNotContain("utPLSQLTests are skipped.");
124+
}
125+
100126
}

‎src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoTest.java‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,67 @@ void default_reporter(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo ut
247247
@Test
248248
@Basedir(UNIT_TESTS + "skip_utplsql_tests")
249249
void skip_utplsql_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
250+
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
251+
}
252+
253+
/**
254+
* Skip Tests
255+
* <p>
256+
* Given : a pom.xml without skipUtplsqlTests and -DskipTests
257+
* When : pom is read
258+
* Then : Tests are skipped
259+
*/
260+
@Test
261+
@Basedir(UNIT_TESTS + "skip_tests")
262+
@MojoParameter(name = "skipTests", value = "true")
263+
void skip_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
264+
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
265+
}
266+
267+
/**
268+
* Maven Test Skip
269+
* <p>
270+
* Given : a pom.xml without skipUtplsqlTests and -Dmaven.test.skip
271+
* When : pom is read
272+
* Then : Tests are skipped
273+
*/
274+
@Test
275+
@Basedir(UNIT_TESTS + "skip_tests")
276+
@MojoParameter(name = "mavenTestSkip", value = "true")
277+
void maven_test_skip(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
278+
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
279+
}
280+
281+
/**
282+
* Skip Tests overridden by skipUtplsqlTests
283+
* <p>
284+
* Given : -DskipTests and -DskipUtplsqlTests=false
285+
* When : pom is read
286+
* Then : utPLSQL tests are not skipped
287+
*/
288+
@Test
289+
@Basedir(UNIT_TESTS + "skip_tests")
290+
@MojoParameter(name = "skipTests", value = "true")
291+
@MojoParameter(name = "mavenTestSkip", value = "true")
292+
@MojoParameter(name = "skipUtplsqlTests", value = "false")
293+
void skip_tests_overridden_by_skip_utplsql_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) {
294+
assertFalse(utPlsqlMojo.isSkipped());
295+
}
296+
297+
/**
298+
* Tests are not skipped by default
299+
* <p>
300+
* Given : a pom.xml without skipUtplsqlTests, skipTests and maven.test.skip
301+
* When : pom is read
302+
* Then : utPLSQL tests are not skipped
303+
*/
304+
@Test
305+
@Basedir(UNIT_TESTS + "skip_tests")
306+
void not_skipped_by_default(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) {
307+
assertFalse(utPlsqlMojo.isSkipped());
308+
}
309+
310+
private static List<String> executeAndGetInfoMessages(UtPlsqlMojo utPlsqlMojo) throws Exception {
250311
List<String> infoMessages = new ArrayList<>();
251312
utPlsqlMojo.setLog(new SystemStreamLog() {
252313
@Override
@@ -257,7 +318,7 @@ public void info(CharSequence content) {
257318

258319
utPlsqlMojo.execute();
259320

260-
assertTrue(infoMessages.contains("utPLSQLTests are skipped."));
321+
return infoMessages;
261322
}
262323

263324
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>maven_test_skip</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>pom</packaging>
10+
11+
<properties>
12+
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
13+
<dbUser>UT3</dbUser>
14+
<dbPass>ut3</dbPass>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.utplsql</groupId>
21+
<artifactId>utplsql-maven-plugin</artifactId>
22+
<version>@project.version@</version>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>test</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>skip_tests</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>pom</packaging>
10+
11+
<properties>
12+
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
13+
<dbUser>UT3</dbUser>
14+
<dbPass>ut3</dbPass>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.utplsql</groupId>
21+
<artifactId>utplsql-maven-plugin</artifactId>
22+
<version>@project.version@</version>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>test</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>skip_tests_overridden_by_skip_utplsql_tests</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>pom</packaging>
10+
11+
<properties>
12+
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
13+
<dbUser>UT3</dbUser>
14+
<dbPass>ut3</dbPass>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.utplsql</groupId>
21+
<artifactId>utplsql-maven-plugin</artifactId>
22+
<version>@project.version@</version>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>test</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>utplsql-maven-plugin-test</artifactId>
8+
<version>3.1.0-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<!-- skipUtplsqlTests, skipTests and maven.test.skip are set by the tests -->
12+
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.utplsql</groupId>
17+
<artifactId>utplsql-maven-plugin</artifactId>
18+
<version>@project.version@</version>
19+
<goals>
20+
<goal>test</goal>
21+
</goals>
22+
<configuration>
23+
<paths>
24+
<path>app</path>
25+
</paths>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>

0 commit comments

Comments
 (0)