#include <stdio.h> FILE* fopen$UNIX2003(const char* filename, const char* mode); size_t fwrite$UNIX2003(const void* ptr, size_t size, size_t nitems, FILE* stream); FILE* fopen$UNIX2003(const char* filename, const char* mode) { return fopen(filename, mode); } size_t fwrite$UNIX2003(const void* ptr, size_t size, size_t nitems, FILE* stream) { return fwrite(ptr, size, nitems, stream); }
#import "MyCalc.h" @implementation MyCalc - (CGFloat)performOperation:(MyMathOperation)operation withA:(CGFloat)a B:(CGFloat)b { CGFloat result = 0.f; switch (operation) { case MyMathOperationAdd: result = a + b; break; case MyMathOperationSubtract: result = a - b; break; case MyMathOperationDivide: result = a / b; break; case MyMathOperationMultiply: result = a * b; break; default: NSLog(@"Unsupported operation"); break; } return result; } - (CGFloat)negate:(CGFloat)number { //this method works incorrectly return number; } @end
- (void)testNegation { CGFloat input = 3; CGFloat expected = -3; CGFloat result = [self.calculator negate:input]; STAssertEquals(result, expected, @"Negation failed. Expected: %f, Actual: %f", expected, result); } - (void)testAddition { CGFloat a = 3; CGFloat b = 4; CGFloat expected = a + b; CGFloat result = [self.calculator performOperation:MyMathOperationAdd withA:a B:b]; STAssertEquals(result, expected, @"Addition failed. Expected: %f, Actual: %f", expected, result); } - (void)testMultiplication { CGFloat a = 14; CGFloat b = 3; CGFloat expected = a * b; CGFloat result = [self.calculator performOperation:MyMathOperationMultiply withA:a B:b]; STAssertEquals(result, expected, @"Addition failed. Expected: %f, Actual: %f", expected, result); }
-: 0:Source:/Users/dlebedev/src/sandbox/Coverage/iOS/iOSCoverage/../../Common/MyCalc.m -: 0:Graph:MyCalc.gcno -: 0:Data:MyCalc.gcda -: 0:Runs:0 -: 0:Programs:0 -: 1:// -: 2:// MyCalc.m -: 3:// iOSCoverage -: 4:// -: 5:// Created by Denis Lebedev on 23.08.12. -: 6:// Copyright (c) 2012 Denis Lebedev. All rights reserved. -: 7:// -: 8: -: 9:#import "MyCalc.h" -: 10: -: 11:@implementation MyCalc -: 12: 2: 13:- (CGFloat)performOperation:(MyMathOperation)operation withA:(CGFloat)a B:(CGFloat)b { 2: 14: CGFloat result = 0.f; -: 15: 2: 16: switch (operation) { -: 17: case MyMathOperationAdd: 1: 18: result = a + b; 1: 19: break; -: 20: case MyMathOperationSubtract: #####: 21: result = a - b; -: 22: #####: 23: break; -: 24: case MyMathOperationDivide: #####: 25: result = a / b; -: 26: #####: 27: break; -: 28: case MyMathOperationMultiply: 1: 29: result = a * b; 1: 30: break; -: 31: default: #####: 32: NSLog(@"Unsupported operation"); #####: 33: break; -: 34: } 2: 35: return result; -: 36:} 1: 37:- (CGFloat)negate:(CGFloat)number { -: 38: //this method works incorrectly 1: 39: return number; -: 40:} -: 41: -: 42:@end
# sudo mkdir -p /usr/local/src; cd /usr/local/src # sudo wget http://downloads.sourceforge.net/ltp/lcov-1.6.tar.gz # sudo tar -xzvf lcov-1.6.tar.gz # cd lcov-1.6
# sudo vim /usr/local/src/lcov-1.6/bin/install.sh</code>
# sudo make install
lcov -t 'Code coverage report' -o report.info -c -d . genhtml -o html-report report.info
#!/bin/sh TARGET_NAME="iOSCoverage" TEST_TARGET_NAME="iOSCoverageTests" BUILD_CONFIG="Debug" SDK_VERSION="iphonesimulator5.1" rm -rf build rm -rf html-report echo Building and running tests xcodebuild -target $TEST_TARGET_NAME OBJECT_FILE_DIR_normal=/build/ TEST_AFTER_BUILD=YES -sdk iphonesimulator5.1 -configuration $BUILD_CONFIG -xcconfig settings.xcconfig echo Copying files mkdir build/gcda cp build/$TARGET_NAME.build/$BUILD_CONFIG-iphonesimulator/$TARGET_NAME.build/Objects-normal/i386/*.gcda build/gcda/ cp build/$TARGET_NAME.build/$BUILD_CONFIG-iphonesimulator/$TARGET_NAME.build/Objects-normal/i386/*.gcno build/gcda/ echo Generating report cd build/gcda lcov -t 'Code coverage report' -o report.info -c -d . cd .. cd .. genhtml -o html-report build/gcda/report.info
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES GCC_GENERATE_TEST_COVERAGE_FILES = YES
Source: https://habr.com/ru/post/150438/
All Articles