Hi,
I'm a C++ guy, and I'm writing a Java app to test part of a product...
I already know I could do this by adding an extra function call, but I was looking for other ways to handle this -- basically I have a Runtest() function where I pass the test I want to run along with the test number... I want to print a header and footer with the test number, but I have multiple return statements in the Runtest() function.
In C++ I could put the header/footer code in another class with the header printed in the constructor and footer printed in the destructor, but I don't think the Java destructors get called as soon as the object goes out of scope. A friend suggested putting the whole thing in a try/finally block with the footer printed in the finally section.
I was wondering if there are any other ways to guarantee that the footer is always printed as soon as the function returns?
I'm a C++ guy, and I'm writing a Java app to test part of a product...
I already know I could do this by adding an extra function call, but I was looking for other ways to handle this -- basically I have a Runtest() function where I pass the test I want to run along with the test number... I want to print a header and footer with the test number, but I have multiple return statements in the Runtest() function.
Code:
public static boolean RunTest( final String testNum,
pkgPreTestSetup.PreTestSetup preTestSetup,
pkgTestSteps.TestSteps testSteps,
pkgExpectedResults.ExpectedResults expectedResults )
{
cout( "**********************************************************************" );
cout( "*** Starting test # " + testNum );
cout( "**********************************************************************" );
preTestSetup.SetTestNum( testNum );
if ( preTestSetup.Run() == false )
{
cout( "ERROR Pre-Test Setup failed for test #" + testNum );
return false;
}
testSteps.SetTestNum( testNum );
if ( testSteps.Run() == false )
{
cout( "ERROR Test Steps failed for test #" + testNum );
return false;
}
if ( expectedResults.Run() == false )
{
cout( "ERROR Expected Results failed for test #" + testNum );
cout( "Expected: '" + expectedResults.ExpectedResultsString() + "'" );
cout( "Actual Results: '" + expectedResults.ActualResultsString() + "'" );
return false;
}
cout( "Test #" + testNum + " passed." );
return true;
}
I was wondering if there are any other ways to guarantee that the footer is always printed as soon as the function returns?