0

In question: Need code examples on how to use org.junit.platform.launcher.listeners problems have been resolved: Exit – program interruption Pause (true) – stops work before receiving Pause (false)

package examples

import org.junit.platform.engine.TestExecutionResult
import org.junit.platform.launcher.TestExecutionListener
import org.junit.platform.launcher.TestIdentifier
import kotlin.system.exitProcess

class CustomTestExecutionListener : TestExecutionListener {
private var shouldPause = false
private var shouldStop = false
private var shouldExit = false
private var shouldSkip = false
override fun executionStarted(testIdentifier: TestIdentifier) {
println("Launcher Started test:  ${testIdentifier.displayName} 
${testIdentifier.source} ")

if (shouldStop) {
    //is it possible to stop launcher and return ???
    // maybe to reset the test plan??
    // Maybe you can cancel Launcher.cancel(true) outside ?
}
}
override fun executionFinished(testIdentifier: TestIdentifier, 
testExecutionResult: TestExecutionResult) {
println("Launcher Finished test: ${testIdentifier.displayName}  
${testExecutionResult.status}")
if (shouldPause) {
    println("Launcher Pausing for Resume")
        while(shouldPause) Thread.sleep(1_000L)
    println("Launcher  Resume")
}
if (shouldExit) {
    println("Launcher Exiting test execution")
    exitProcess(0)
}
}

/**
 * @param shouldPause must be:
 * true - Pause
 * false - Resume - run
 */
fun setShouldPause(shouldPause: Boolean) {
this.shouldPause = shouldPause
}
fun setShouldStop(shouldStop: Boolean) {
this.shouldStop = shouldStop
}
fun setShouldExit(shouldExit: Boolean) {
this.shouldExit = shouldExit
}
fun setShouldSkip(shouldSkip: Boolean) {
this.shouldSkip = shouldSkip
 }
}

Remaining problems: Stop – do not stop the application, but finish the work Launcher return to his challenge - Is it possible to stop launcher and return??? - maybe to reset the test plan?? - Maybe you can cancel Launcher.cancel(true) outside? Optional: How to give a command Launcher – skip test? Thanks for the help

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.