Reputation: 139
I am having trouble with writing JUnit test for this case. I get runtime error. I tried
import junit.framework.*;
import student.TestCase;
public class MemmanTest extends TestCase {
public MemmanTest() {
// empty
}
public void testMemmanSystemIn() throws Exception {
setSystemIn("10 32 P1sampleInput.txt");
Memman.main(null);
assertTrue(systemOut().getHistory(), "P1sampleOutput.txt");
}
}`
So I can check the input file and the output file is same. (actually when I run the acutal program, its same, but I just cannot make the test case.)
Upvotes: 0
Views: 324
Reputation: 42174
That's not how you call main.
If you don't specify any arguments, the args variable is not null; it's an empty array.
Memman.main(new String[]{});
You could also use varargs instead of an array, then just call main with no arguments.
Edit: As Holger pointed out, it looks like you're trying to use setSystemIn() to pass arguments into the main() method. That won't work. Instead, you should just pass them into the array:
Memman.main(new String[]{"10", "32", "P1sampleInput.txt"});
This is the first result for googling "junit pass arguments to main": Passing command line arguments to JUnit in Eclipse
Upvotes: 3