0

I write simple main class, which requires two arguments "app firstOne secondOne". I want write Junit test to check, that user put right count of arguments

public static void main(String[] args) {
        if (args.length == 2) {
            someMethod();

            System.exit(1);
        } else
            System.exit(0);
    }

And i want check which exit status return.

I found solmething using

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

But it do not find lib (I am using now Junit version 4.13.beta-1)

  org.junit.contrib.java.lang.system.ExpectedSystemExit

Have You any idea how to write test which will check right number of argument passed to program?

ACz
  • 567
  • 5
  • 22
  • 2
    1 Google for ExpectedSystemExit. 2. Click on the second link returned. Bingo: https://stefanbirkner.github.io/system-rules/ – JB Nizet Dec 08 '18 at 12:13
  • Possible duplicate of [How do I get the bash command exit code from a Process run from within Java?](https://stackoverflow.com/questions/5886935/how-do-i-get-the-bash-command-exit-code-from-a-process-run-from-within-java) – Robin Green Dec 08 '18 at 12:27
  • @RobinGreen Nope, not duplicate – ACz Dec 08 '18 at 18:08

1 Answers1

1

You should add the System Rules library.

Maven:

<dependency>
    <groupId>com.github.stefanbirkner</groupId>
    <artifactId>system-rules</artifactId>
    <version>1.19.0</version>
    <scope>test</scope>
</dependency>

Gradle:

testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.19.0'
Mohsen
  • 4,536
  • 2
  • 27
  • 49