Mac unit testing

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
Is it possible to reduce the verbosity of the unit testing output in Xcode 5?

I have one test with two asserts and I get all of this
Code:
2014-02-23 14:07:09.254 MyTextStorage[44260:303] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /.../MyTestStorage.savedState
Test Suite 'All tests' started at 2014-02-23 13:07:09 +0000
Test Suite 'MyUnitTests.xctest' started at 2014-02-23 13:07:09 +0000
Test Suite 'MyTest' started at 2014-02-23 13:07:09 +0000
Test Case '-[MyTest testExample]' started.
Test Case '-[MyTest testExample]' passed (3.962 seconds).
Test Suite 'MyTest' finished at 2014-02-23 13:07:13 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 3.962 (3.962) seconds
Test Suite 'MyUnitTests.xctest' finished at 2014-02-23 13:07:13 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 3.962 (3.963) seconds
Test Suite 'All tests' finished at 2014-02-23 13:07:13 +0000.
Executed 1 test, with 0 failures (0 unexpected) in 3.962 (3.963) seconds
What I want to see is something short like this:
Code:
Test Case '-[MyTest testExample]' passed/failed.
My assert statement:
Code:
XCTAssert([[textStorage string] isEqualToString:@"test"]);
 

gnasher729

macrumors P6
Nov 25, 2005
17,178
3,134
Think a bit ahead to the future, when you have a few hundred unit tests. You run them after every change you make. You don't care about unit tests that are passing. You _only_ care about unit tests that are failing.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
Think a bit ahead to the future, when you have a few hundred unit tests. You run them after every change you make. You don't care about unit tests that are passing. You _only_ care about unit tests that are failing.
Yes, indeed. So why show me all this text? I only want to see the output of the ones that failed. Not that they have started and ended successfully.

I want to see the output as specified by format. Nothing more, nothing less.
XCTAssert(<test>,<format>)
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,709
3,999
Yes, indeed. So why show me all this text? I only want to see the output of the ones that failed. Not that they have started and ended successfully.

I want to see the output as specified by format. Nothing more, nothing less.
XCTAssert(<test>,<format>)
I'm not sure why it really matters - I just look for the green and red symbols to see what passed and failed, along with the big checkmark or X that appears at the end of running the tests.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
I'm not sure why it really matters - I just look for the green and red symbols to see what passed and failed, along with the big checkmark or X that appears at the end of running the tests.
And I want to see my code specific output when a test fails without having to look for it. It provides more information at a glance. It helps me hunt down bugs. I don't want to spend time looking for a specific output line. So it matters to me.
 

chown33

Moderator
Staff member
Aug 9, 2009
8,497
4,459
Pale blue comma
And I want to see my code specific output when a test fails without having to look for it. It provides more information at a glance. It helps me hunt down bugs. I don't want to spend time looking for a specific output line. So it matters to me.
The unit-test framework in Xcode 5 is XCTest. It's based on OCUnit.

Here's the man page for the 'xctest' command:
https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man1/xctest.1.html

It mentions a script located in /Developer/Tools/RunTargetUnitTests that runs the unit tests. Look for that, and see if it's emitting the prologue and epilogue text. If so, you may need to add a verbosity-control flag, or just comment-out the cmds that emit the text.

The 'xctest' man page also links to a man page for RunTargetUnitTests.

Also see the man page for the 'otest' cmd, which is the actual OCUnit executable. If you can't figure out how to tell 'otest' to be less verbose, you may have to change its source.

The source for OCUnit is available. Google search terms: ocunit source

Since many of the parameters to XCTest and OCUnit are passed as environment variables, you might consider adding an env-var to control verbosity. See 'man getenv'; it's a standard C library function. Then you can set or clear the env-var in your project's build settings, and it should propagate all the way into xctest and otest.