Re: Unit testing Cocoa-Java applications?
Re: Unit testing Cocoa-Java applications?
- Subject: Re: Unit testing Cocoa-Java applications?
- From: Chris Hanson <email@hidden>
- Date: Sun, 18 May 2003 08:03:33 -0500
Another update: I now have the application quit after the unit tests
are run, and use a shell script build phase to run the tests in my Test
target.
Here's the new runAllUnitTestsIfRequested() method:
public void runAllUnitTestsIfRequested()
{
Boolean runAllUnitTests;
runAllUnitTests = new Boolean((String)
NSSystem.environment().valueForKey("RunAllUnitTests"));
if (runAllUnitTests.booleanValue() == true) {
try {
// This is the same as
// TestAll.runAllUnitTests();
// only it's fully dynamic, and will fail
// safely in the release build.
Class testAllClass = Class.forName("TestAll");
Method runAllUnitTestsMethod =
testAllClass.getMethod("runAllUnitTests", null);
runAllUnitTestsMethod.invoke(null, null);
}
catch (Exception classNotFound) {
// Do nothing
}
finally {
NSApplication.sharedApplication().terminate(this);
}
}
}
Here's the shell script, RunAllUnitTests.sh, that I use to run the
application with testing configured:
#!/bin/sh
# Set up the environment
RunAllUnitTests=true
export RunAllUnitTests
# Run the executable
"${SYMROOT}/${PRODUCT_NAME}.${WRAPPER_EXTENSION}/Contents/MacOS/
${PRODUCT_NAME}"
The shell script build phase I created just contains ".
$SRCROOT/RunAllUnitTests.sh", which runs the script regardless of its x
permission.
Using this, I now have my unit tests running every time I build.
The only two things left to make it fancier are to figure out how to
have the test system automatically discover all test suites (so I don't
have to add them to TestAll.suite() by hand), and to generate its
output in a format that Project Builder can parse so it shows failures
in red in the build window.
-- Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.