31. Escribiendo unit tests
con OCUnit
• Cada Test Suite es una clase que hereda de
SenTestCase
• Cada Test Case debe ser un método con el
prefijo test
• setUp y tearDown son opcionales
33. Console output
2011-12-09 12:43:01.394 HelloWorld[2858:fb03] Applications are expected to have a
root view controller at the end of application launch
Test Suite 'All tests' started at 2011-12-09 11:43:01 +0000
Test Suite '/Users/hermespique/Library/Developer/Xcode/DerivedData/HelloWorld-
ezilismrgmrzecbbsndapbyeczre/Build/Products/Debug-iphonesimulator/
HelloWorldTests.octest(Tests)' started at 2011-12-09 11:43:01 +0000
Test Suite 'HelloWorldTests' started at 2011-12-09 11:43:01 +0000
Test Case '-[HelloWorldTests testExample]' started.
/Users/hermespique/Documents/workspace/HelloWorld/HelloWorldTests/
HelloWorldTests.m:33: error: -[HelloWorldTests testExample] : Unit tests are not
implemented yet in HelloWorldTests
Test Case '-[HelloWorldTests testExample]' failed (0.000 seconds).
Test Suite 'HelloWorldTests' finished at 2011-12-09 11:43:01 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.000) seconds
Test Suite '/Users/hermespique/Library/Developer/Xcode/DerivedData/HelloWorld-
ezilismrgmrzecbbsndapbyeczre/Build/Products/Debug-iphonesimulator/
HelloWorldTests.octest(Tests)' finished at 2011-12-09 11:43:01 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.000) seconds
Test Suite 'All tests' finished at 2011-12-09 11:43:01 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.001) seconds
37. GHUnit
• Framework de Unit Testing para Obj-C
• Open-source: github.com/gabriel/gh-unit
• GUI!
• Compatible con OCUnit
38.
39. #import <GHUnitIOS/GHUnit.h>
@interface ExampleTest : GHTestCase
@end
@implementation ExampleTest
- (BOOL)shouldRunOnMainThread {
return NO;
}
- (void)setUpClass {
// Run at start of all tests in the class
}
- (void)setUp {
// Run before each test method
}
- (void)tearDown {
// Run after each test method
}
- (void)tearDownClass {
// Run at end of all tests in the class
}
- (void)testFoo {
NSString *a = @"foo";
GHAssertNotNil(a, nil);
}
@end
49. OCUnit vs GHUnit
OCUnit GHUnit
Integración con
Built-in Manual
XCode
Contextual /
Resultados Consola / GUI
Consola
Más macros
Programación
GHAsyncTestCase
Todo, selección o
Ejecución Todo
fallidos