Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,24 @@ utPLSQL reports coverage per source file instead of per database object. The plu

## Skipping tests

Set `skipUtplsqlTests` to `true` in the plugin configuration or on the command line:
The utPLSQL tests are skipped together with other tests by Maven's standard `-DskipTests` or `-Dmaven.test.skip=true`:

```bash
mvn install -DskipTests
```

To skip only the utPLSQL tests, set `skipUtplsqlTests` to `true` in the plugin configuration or on the command line:

```bash
mvn install -DskipUtplsqlTests=true
```

Maven's `-DskipTests` does not skip utPLSQL tests.
`skipUtplsqlTests` takes precedence over `skipTests` and `maven.test.skip`. To skip other tests but run the utPLSQL
tests, set it to `false`:

```bash
mvn install -DskipTests -DskipUtplsqlTests=false
```

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

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

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

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

## Comparison with utPLSQL-cli

Expand Down
28 changes: 25 additions & 3 deletions src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ public class UtPlsqlMojo extends AbstractMojo {
@Parameter(defaultValue = "${maven.test.failure.ignore}")
boolean ignoreFailure;

@Parameter(property = "skipUtplsqlTests", defaultValue = "false")
boolean skipUtplsqlTests;
/**
* Skips the utPLSQL tests when true, runs them when false.
* When not set, the tests are skipped together with other tests by skipTests or maven.test.skip.
*/
@Parameter(property = "skipUtplsqlTests")
Boolean skipUtplsqlTests;

@Parameter(property = "skipTests", defaultValue = "false")
boolean skipTests;

@Parameter(property = "maven.test.skip", defaultValue = "false")
boolean mavenTestSkip;

@Parameter
boolean dbmsOutput;
Expand All @@ -141,7 +151,7 @@ public class UtPlsqlMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException {
if (skipUtplsqlTests) {
if (isSkipped()) {
getLog().info("utPLSQLTests are skipped.");
} else {
getLog().debug("Java API Version = " + JavaApiVersionInfo.getVersion());
Expand Down Expand Up @@ -231,6 +241,18 @@ public void execute() throws MojoExecutionException {
}
}

/**
* skipUtplsqlTests takes precedence, so -DskipTests -DskipUtplsqlTests=false skips other tests but runs utPLSQL tests.
*
* @return true when the utPLSQL tests should not be run
*/
boolean isSkipped() {
if (skipUtplsqlTests != null) {
return skipUtplsqlTests;
}
return skipTests || mavenTestSkip;
}

private Connection createConnection() throws SQLException {
if (isEmpty(url)) {
url = System.getProperty("dbUrl");
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.soebes.itf.jupiter.extension.MavenGoal;
import com.soebes.itf.jupiter.extension.MavenJupiterExtension;
import com.soebes.itf.jupiter.extension.MavenTest;
import com.soebes.itf.jupiter.extension.SystemProperty;
import com.soebes.itf.jupiter.maven.MavenExecutionResult;

import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
Expand Down Expand Up @@ -97,4 +98,29 @@
assertThatReportsAreGeneratedAsExpected(result, "sonar-test-report.xml", "coverage-sonar-report.xml");
}

@MavenTest
@SystemProperty(value = "skipTests", content = "true")
void skip_tests(MavenExecutionResult result) {
assertThat(result).isSuccessful();

assertThat(result.getMavenLog()).info().contains("utPLSQLTests are skipped.");
}

@MavenTest
@SystemProperty(value = "maven.test.skip", content = "true")
void maven_test_skip(MavenExecutionResult result) {

Check warning on line 111 in src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoIT.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Update this method so that its implementation is not identical to "skip_tests" on line 103.

See more on https://sonarcloud.io/project/issues?id=utPLSQL_utPLSQL-maven-plugin&issues=AaDkH3PHAQ53IhMwUvOP&open=AaDkH3PHAQ53IhMwUvOP&pullRequest=83
assertThat(result).isSuccessful();

assertThat(result.getMavenLog()).info().contains("utPLSQLTests are skipped.");
}

@MavenTest
@SystemProperty(value = "skipTests", content = "true")
@SystemProperty(value = "skipUtplsqlTests", content = "false")
void skip_tests_overridden_by_skip_utplsql_tests(MavenExecutionResult result) {
assertThat(result).isSuccessful();

assertThat(result.getMavenLog()).info().doesNotContain("utPLSQLTests are skipped.");
}

}
63 changes: 62 additions & 1 deletion src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,67 @@ void default_reporter(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo ut
@Test
@Basedir(UNIT_TESTS + "skip_utplsql_tests")
void skip_utplsql_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
}

/**
* Skip Tests
* <p>
* Given : a pom.xml without skipUtplsqlTests and -DskipTests
* When : pom is read
* Then : Tests are skipped
*/
@Test
@Basedir(UNIT_TESTS + "skip_tests")
@MojoParameter(name = "skipTests", value = "true")
void skip_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
}

/**
* Maven Test Skip
* <p>
* Given : a pom.xml without skipUtplsqlTests and -Dmaven.test.skip
* When : pom is read
* Then : Tests are skipped
*/
@Test
@Basedir(UNIT_TESTS + "skip_tests")
@MojoParameter(name = "mavenTestSkip", value = "true")
void maven_test_skip(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) throws Exception {
assertTrue(executeAndGetInfoMessages(utPlsqlMojo).contains("utPLSQLTests are skipped."));
}

/**
* Skip Tests overridden by skipUtplsqlTests
* <p>
* Given : -DskipTests and -DskipUtplsqlTests=false
* When : pom is read
* Then : utPLSQL tests are not skipped
*/
@Test
@Basedir(UNIT_TESTS + "skip_tests")
@MojoParameter(name = "skipTests", value = "true")
@MojoParameter(name = "mavenTestSkip", value = "true")
@MojoParameter(name = "skipUtplsqlTests", value = "false")
void skip_tests_overridden_by_skip_utplsql_tests(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) {
assertFalse(utPlsqlMojo.isSkipped());
}

/**
* Tests are not skipped by default
* <p>
* Given : a pom.xml without skipUtplsqlTests, skipTests and maven.test.skip
* When : pom is read
* Then : utPLSQL tests are not skipped
*/
@Test
@Basedir(UNIT_TESTS + "skip_tests")
void not_skipped_by_default(@InjectMojo(goal = "test", pom = "pom.xml") UtPlsqlMojo utPlsqlMojo) {
assertFalse(utPlsqlMojo.isSkipped());
}

private static List<String> executeAndGetInfoMessages(UtPlsqlMojo utPlsqlMojo) throws Exception {
List<String> infoMessages = new ArrayList<>();
utPlsqlMojo.setLog(new SystemStreamLog() {
@Override
Expand All @@ -257,7 +318,7 @@ public void info(CharSequence content) {

utPlsqlMojo.execute();

assertTrue(infoMessages.contains("utPLSQLTests are skipped."));
return infoMessages;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.utplsql</groupId>
<artifactId>maven_test_skip</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
<dbUser>UT3</dbUser>
<dbPass>ut3</dbPass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.utplsql</groupId>
<artifactId>skip_tests</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
<dbUser>UT3</dbUser>
<dbPass>ut3</dbPass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.utplsql</groupId>
<artifactId>skip_tests_overridden_by_skip_utplsql_tests</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<dbUrl>jdbc:oracle:thin:@//localhost:1521/FREEPDB1</dbUrl>
<dbUser>UT3</dbUser>
<dbPass>ut3</dbPass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
30 changes: 30 additions & 0 deletions src/test/resources/unit-tests/skip_tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin-test</artifactId>
<version>3.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<!-- skipUtplsqlTests, skipTests and maven.test.skip are set by the tests -->

<build>
<plugins>
<plugin>
<groupId>org.utplsql</groupId>
<artifactId>utplsql-maven-plugin</artifactId>
<version>@project.version@</version>
<goals>
<goal>test</goal>
</goals>
<configuration>
<paths>
<path>app</path>
</paths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading