Issue
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?
Solution
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'
Answered By - Mohsen
Answer Checked By - Marilyn (JavaFixing Volunteer)