anchor.diff:          MyApp.main();
       }
   }
  +----
  +
  +.Kotlin/Kotest
  +[source,kotlin,role=secondary]
  +----
  +import io.kotest.assertions.throwables.shouldThrow
  +import io.kotest.core.spec.style.StringSpec
  +import io.kotest.extensions.system.*
  +import io.kotest.matchers.shouldBe
  +// ...
  +
  +class SystemExitTest : StringSpec() {
  +
  +    override fun listeners() = listOf(SpecSystemExitListener)
  +
  +    init {
  +        "Picocli app should exit process with return code 42" {
  +            shouldThrow<SystemExitException> {
  +                main(arrayOf())
  +            }.exitCode shouldBe 42
  +        }
  +    }
  +}
  +
  +@Command
  +class PicocliApp : Callable<Int> {
  +    override fun call(): Int {
  +        return 42
  +    }
  +}
  +
  +fun main(args: Array<String>) : Unit = exitProcess(CommandLine(PicocliApp()).execute(*args))
   ----
   
   === Testing Environment Variables
  
positive.code: 
  === Testing the Exit Code
  Testing the exit code of applications that call `System.exit` can be tricky but is not impossible.
  
  ==== Java 8+ and `catchSystemExit`
  Applications that use JUnit 5 or Java 8+ can use Stephan Birkner's https://github.com/stefanbirkner/system-lambda[System-Lambda] project for testing the https://github.com/stefanbirkner/system-lambda#systemexit[exit code].
  For example:
  
  [source,java]
  ----
  import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
  // ...
  
negative.code: }
  ----
  
  .Java/Junit 5
  [source,java,role=secondary]
  ----
  import com.ginsberg.junit.exit.ExpectSystemExitWithStatus;
  import org.junit.jupiter.api.Test;
  // ...
  
  class MyTest {
      @Command
      static class MyApp implements Callable<Integer> {
          @Override
          public Integer call() throws Exception {
              System.out.println("Hi");
              return 42;
          }
          public static void main (String[] args) {
              System.exit(new CommandLine(new MyApp()).execute(args));
          }
      }
  
      @Test
      @ExpectSystemExitWithStatus(42)
      void testMyAppExit() {
          MyApp.main(new String[] {});
      }
  }
  ----
  
  .Java/Junit 4
  [source,java,role=secondary]
  ----
  import org.junit.Rule;
  import org.junit.Test;
  