Generates and convert JUnit test reports for xunit-view

This commit is contained in:
Erik C. Thauvin 2025-05-14 22:01:57 -07:00
parent fc3e641793
commit 820ec736bb
Signed by: erik
GPG key ID: 776702A6A2DA330E
7 changed files with 96 additions and 44 deletions

View file

@ -3,6 +3,7 @@ bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT
bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.4-SNAPSHOT bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.4-SNAPSHOT
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.5
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10 bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES

View file

@ -33,14 +33,10 @@ package net.thauvin.erik.bitly;
import rife.bld.BuildCommand; import rife.bld.BuildCommand;
import rife.bld.Project; import rife.bld.Project;
import rife.bld.extension.CompileKotlinOperation; import rife.bld.extension.*;
import rife.bld.extension.DetektOperation;
import rife.bld.extension.DokkaOperation;
import rife.bld.extension.JacocoReportOperation;
import rife.bld.extension.dokka.LoggingLevel; import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat; import rife.bld.extension.dokka.OutputFormat;
import rife.bld.extension.dokka.SourceSet; import rife.bld.extension.dokka.SourceSet;
import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.operations.exceptions.ExitStatusException; import rife.bld.operations.exceptions.ExitStatusException;
import rife.bld.publish.PomBuilder; import rife.bld.publish.PomBuilder;
import rife.bld.publish.PublishDeveloper; import rife.bld.publish.PublishDeveloper;
@ -50,6 +46,8 @@ import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
import java.util.logging.Level; import java.util.logging.Level;
@ -68,12 +66,14 @@ public class BitlyShortenBuild extends Project {
version = version(2, 0, 1, "SNAPSHOT"); version = version(2, 0, 1, "SNAPSHOT");
javaRelease = 11; javaRelease = 11;
downloadSources = true; downloadSources = true;
autoDownloadPurge = true; autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL); repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
var okHttp = version(4, 12, 0); var okHttp = version(4, 12, 0);
final var kotlin = version(2, 1, 20); final var kotlin = version(2, 1, 21);
scope(compile) scope(compile)
// Kotlin // Kotlin
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin)) .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin))
@ -140,10 +140,9 @@ public class BitlyShortenBuild extends Project {
@BuildCommand(summary = "Compiles the Kotlin project") @BuildCommand(summary = "Compiles the Kotlin project")
@Override @Override
public void compile() throws Exception { public void compile() throws Exception {
new CompileKotlinOperation() var op = new CompileKotlinOperation().fromProject(this);
.fromProject(this) op.compileOptions().languageVersion("1.9").verbose(true);
.compileOptions(new CompileOptions().verbose(true)) op.execute();
.execute();
} }
@BuildCommand(summary = "Checks source with Detekt") @BuildCommand(summary = "Checks source with Detekt")
@ -220,4 +219,25 @@ public class BitlyShortenBuild extends Project {
PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(), PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(),
new File(workDirectory, "pom.xml")); new File(workDirectory, "pom.xml"));
} }
@Override
public void test() throws Exception {
var testResultsDir = "build/test-results/test/";
var op = testOperation().fromProject(this);
op.testToolOptions().reportsDir(new File(testResultsDir));
op.execute();
var xunitViewer = new File("/usr/bin/xunit-viewer");
if (xunitViewer.exists() && xunitViewer.canExecute()) {
var reportsDir = "build/reports/tests/test/";
Files.createDirectories(Path.of(reportsDir));
new ExecOperation()
.fromProject(this)
.command(xunitViewer.getPath(), "-r", testResultsDir, "-o", reportsDir + "index.html")
.execute();
}
}
} }

View file

@ -0,0 +1,52 @@
/*
* BeforeAll.kt
*
* Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.bitly
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.ConsoleHandler
import java.util.logging.Level
class BeforeAll : BeforeAllCallback {
private val isFirstTime: AtomicBoolean = AtomicBoolean(true)
override fun beforeAll(context: ExtensionContext?) {
if (isFirstTime.getAndSet(false)) {
with(Utils.logger) {
addHandler(ConsoleHandler().apply { level = Level.FINE })
level = Level.FINE
}
}
}
}

View file

@ -1,5 +1,5 @@
/* /*
* BitlinksTest.kt * BitlinksTests.kt
* *
* Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net)
* *
@ -41,18 +41,18 @@ import net.thauvin.erik.bitly.config.deeplinks.CreateDeeplinks
import net.thauvin.erik.bitly.config.deeplinks.UpdateDeeplinks import net.thauvin.erik.bitly.config.deeplinks.UpdateDeeplinks
import net.thauvin.erik.bitly.config.deeplinks.enums.InstallType import net.thauvin.erik.bitly.config.deeplinks.enums.InstallType
import net.thauvin.erik.bitly.config.deeplinks.enums.Os import net.thauvin.erik.bitly.config.deeplinks.enums.Os
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable
import org.junit.jupiter.api.extension.ExtendWith
import java.io.File import java.io.File
import java.util.logging.Level
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
import kotlin.test.assertTrue import kotlin.test.assertTrue
class BitlinksTest { @ExtendWith(BeforeAll::class)
class BitlinksTests {
private val bitly = with(File("local.properties")) { private val bitly = with(File("local.properties")) {
if (exists()) { if (exists()) {
Bitly(toPath()) Bitly(toPath())
@ -63,16 +63,6 @@ class BitlinksTest {
private val longUrl = "https://erik.thauvin.net/blog" private val longUrl = "https://erik.thauvin.net/blog"
private val shortUrl = "https://bit.ly/380ojFd" private val shortUrl = "https://bit.ly/380ojFd"
companion object {
@JvmStatic
@BeforeAll
fun before() {
with(Utils.logger) {
level = Level.FINE
}
}
}
@Nested @Nested
@DisplayName("Bitlinks Tests") @DisplayName("Bitlinks Tests")
inner class BitlinksTests { inner class BitlinksTests {
@ -319,7 +309,7 @@ class BitlinksTest {
@Test @Test
@EnabledIfEnvironmentVariable(named = "CI", matches = "true") @EnabledIfEnvironmentVariable(named = "CI", matches = "true")
fun `Token not specified on CI`() { fun `Token not specified on CI`() {
val test = Bitly(Constants.EMPTY) // to void picking up the environment variable val test = Bitly(Constants.EMPTY) // to avoid picking up the environment variable
assertFailsWith(IllegalArgumentException::class) { assertFailsWith(IllegalArgumentException::class) {
test.bitlinks().shorten(longUrl) test.bitlinks().shorten(longUrl)

View file

@ -1,5 +1,5 @@
/* /*
* BitlyTest.kt * BitlyTests.kt
* *
* Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net)
* *
@ -39,16 +39,16 @@ import assertk.assertions.prop
import net.thauvin.erik.bitly.Utils.removeHttp import net.thauvin.erik.bitly.Utils.removeHttp
import net.thauvin.erik.bitly.Utils.toEndPoint import net.thauvin.erik.bitly.Utils.toEndPoint
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.extension.ExtendWith
import java.io.File import java.io.File
import java.util.logging.Level
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
class BitlyTest { @ExtendWith(BeforeAll::class)
class BitlyTests {
private val bitly = with(File("local.properties")) { private val bitly = with(File("local.properties")) {
if (exists()) { if (exists()) {
Bitly(toPath()) Bitly(toPath())
@ -58,17 +58,6 @@ class BitlyTest {
} }
private val shortUrl = "https://bit.ly/380ojFd" private val shortUrl = "https://bit.ly/380ojFd"
companion object {
@JvmStatic
@BeforeAll
fun before() {
with(Utils.logger) {
level = Level.FINE
}
}
}
@Nested @Nested
@DisplayName("API Call Tests") @DisplayName("API Call Tests")
inner class ApiCallTests { inner class ApiCallTests {

View file

@ -1,5 +1,5 @@
/* /*
* ConfigTest.kt * ConfigTests.kt
* *
* Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net)
* *
@ -46,7 +46,7 @@ import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Nested
import kotlin.test.Test import kotlin.test.Test
class ConfigTest { class ConfigTests {
@Nested @Nested
@DisplayName("Build Configuration Tests") @DisplayName("Build Configuration Tests")
inner class BuildConfigurationTests { inner class BuildConfigurationTests {

View file

@ -1,5 +1,5 @@
/* /*
* DeeplinksTest.kt * DeeplinksTests.kt
* *
* Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net) * Copyright 2020-2025 Erik C. Thauvin (erik@thauvin.net)
* *
@ -43,7 +43,7 @@ import org.junit.Test
import java.time.ZoneId import java.time.ZoneId
import java.time.ZonedDateTime import java.time.ZonedDateTime
class DeeplinksTest { class DeeplinksTests {
@Test @Test
fun `Create deeplink`() { fun `Create deeplink`() {
val deeplinks = CreateDeeplinks().apply { val deeplinks = CreateDeeplinks().apply {