unit testing

Discussion in 'Mac Programming' started by MrFusion, Feb 23, 2014.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    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"]);
    
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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.
     
  3. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    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>)
     
  4. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    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.
     
  5. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #5
    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.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    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.
     

Share This Page