This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I have a Standalone program which has a void method and will exit if any validation fails.If i give the input which will fail in validation , Test case has stopped and it is not continuing to the next case.
Please help to write the proper test case for this situation.( I am very new to JUNIT)
I have used an approach similar to what Greg suggested. Extending the class under test (CUT) and overriding one or more methods works really nicely, assuming the CUT is not declared as final. However, throwing an exception is expensive and increases test execution time slightly. Since unit tests should run as fast as possible, I'd prefer to avoid throwing an exception outside of the actual CUT if I can help it. I would just add a boolean field in the extended class and set it to true in the redefined exit() method. No need to add a getter, just access the boolean field directly from the test case.