Skip to content

Commit

Permalink
Added support for JaCoCo extension. Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Apr 4, 2024
1 parent 63635f4 commit 4d4479b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# [bld](https://rife2.com/bld) Extension to Run Tests with [TestNG](https://testng.org/)


[![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
[![bld](https://img.shields.io/badge/1.9.0-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld)
Expand All @@ -13,29 +12,11 @@ To install, please refer to the [extensions documentation](https://github.com/ri
To run the tests with TestNG, add the following to your build file:

```java
@BuildCommand(summary = "Tests the project with TestNG")
public void testng() throws Exception {
new TestNgOperation()
.fromProject(this)
.packages("com.example")
.execute();
}
```

```console
./bld compile testng
```

You could also override the default `test` command:

```java
@BuildCommand(summary = "Tests the project with TestNG")
public void test throws Exception {
new TestNgOperation()
.fromProject(this)
.suites("src/test/resources/testng.xml")
.verbose(2)
.execute();
@Override
public TestOperation<?, ?> testOperation() {
return new TestNgOperation()
.fromProject(this)
.packages("com.example");
}
```

Expand Down
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ Compile and Run Tests with TestNG
```console
./bld compile test
```

Compile and Generate JaCoCo Reports

```console
./bld compile jacoco
```
3 changes: 2 additions & 1 deletion examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.extensions=com.uwyn.rife2:bld-testng:0.9.4
bld.extensions=com.uwyn.rife2:bld-testng:0.9.5
bld.extension.jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation=
bld.sourceDirectories=
Expand Down
23 changes: 17 additions & 6 deletions examples/src/bld/java/com/example/ExamplesBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import rife.bld.BaseProject;
import rife.bld.BuildCommand;
import rife.bld.extension.JacocoReportOperation;
import rife.bld.extension.TestNgOperation;
import rife.bld.operations.TestOperation;

import java.io.IOException;
import java.util.List;

import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
Expand All @@ -13,32 +16,40 @@
* Example build.
*
* <ul style="list-style-type:none">
* <li>./bld compile test</li>
* <li>{@code ./bld compile test}</li>
* <li>{@code ./bld compile jacoco}</li>
* </ul>
*/
public class ExamplesBuild extends BaseProject {
@Override
public TestOperation<?, ?> testOperation() {
return new TestNgOperation()
.fromProject(this)
.packages("com.example");
}

public ExamplesBuild() {
pkg = "com.example";
name = "Examples";
version = version(0, 1, 0);

javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;

repositories = List.of(MAVEN_CENTRAL);

scope(test).include(dependency("org.testng", "testng", version(7, 9, 0)));
}

public static void main(String[] args) {
new ExamplesBuild().start(args);
}

@BuildCommand(summary = "Tests the project with TestNG")
public void test() throws Exception {
new TestNgOperation()
@BuildCommand(summary = "Generates Jacoco Reports")
public void jacoco() throws IOException {
new JacocoReportOperation()
.fromProject(this)
.packages("com.example")
.execute();
}
}
4 changes: 2 additions & 2 deletions src/bld/java/rife/bld/extension/TestNgOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestNgOperationBuild extends Project {
public TestNgOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-testng";
version = version(0, 9, 4);
version = version(0, 9, 5);

javaRelease = 17;
downloadSources = true;
Expand Down Expand Up @@ -76,7 +76,7 @@ public TestNgOperationBuild() {
.license(
new PublishLicense()
.name("The Apache License, Version 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt")
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
)
.scm(
new PublishScm()
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/rife/bld/extension/TestNgOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package rife.bld.extension;

import rife.bld.BaseProject;
import rife.bld.operations.AbstractProcessOperation;
import rife.bld.operations.TestOperation;

import java.io.File;
import java.io.IOException;
Expand All @@ -37,7 +37,7 @@
* @since 1.0
*/
@SuppressWarnings("PMD.TestClassWithoutTestCases")
public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> {
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
/**
* The run options.
Expand Down Expand Up @@ -151,11 +151,12 @@ protected List<String> executeConstructProcessCommandList() {
}

if (!options.containsKey("-d")) {
options.put("d", Path.of(project.buildDirectory().getPath(), "test-output").toString());
options.put("-d", Path.of(project.buildDirectory().getPath(), "test-output").toString());
}

final List<String> args = new ArrayList<>();
args.add(javaTool());
args.addAll(this.javaOptions());

args.add("-cp");
if (testClasspath.isEmpty()) {
Expand Down

0 comments on commit 4d4479b

Please sign in to comment.