티스토리 뷰

반응형

[1] XCode에서 보기 

 

Edit Scheme에 들어가서 code coverage를 체크해주고

 

 

테스트를 돌리면 XCODE에서 여기 말풍선 눌러서 테스트 결과를 볼 수 있잖아요,,,! 

 

 

Xcode말고 파일로도 볼 수 있습니다..!

XcodeCode coverage reports를 derived data directory(~/Library/Developer/Xcode/DerivedData)에 생성합니다.

 

 

정확히 말하면  DerivedData -> GithubActionTest -> Logs -> Test 디렉토리에 만들어줍니다. 

 

 

저 파일을 누르면 XCODE가 열리고 이런 리포트화면을 보여주더라구요

 

 

 

[2] 터미널에 출력해보기 

 

medium.com/xcblog/xccov-xcode-code-coverage-report-for-humans-466a4865aa18

 

xccov: Xcode Code Coverage Report for Humans

Originally Posted on XCBlog Here

medium.com

 

developer.apple.com/videos/play/wwdc2018/403/

 

What's New in Testing - WWDC 2018 - Videos - Apple Developer

Hear about exciting improvements to code coverage, including how you can build your own automation on top of Xcode's coverage reports...

developer.apple.com

 

 

위의 두개를 참고해서 

xcrun xccov view

를 사용하려고 했더니 잘안되더라구요ㅠㅠ

 

 

이렇게 테스트를 돌리고

xcodebuild test -workspace /Users/kakao/Documents/GithubActionTest/GithubActionTest.xcworkspace -scheme 'GithubActionTest' -derivedDataPath ./Build/ -destination 'platform=iOS Simulator,name=iPhone 8' -enableCodeCoverage YES

 

또는 이렇게 돌리면 derivedData폴더가 프로젝트안에 생성된다고 합니다. 

xcodebuild test -workspace /Users/kakao/Documents/GithubActionTest/GithubActionTest.xcworkspace -scheme 'GithubActionTest' -destination 'platform=iOS Simulator,name=iPad Pro (9.7-inch)' -enableCodeCoverage YES clean build test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

 

 

 

 

 

그다음 report 를 보여달라는 명령을 치면

xcrun xccov view –report  /Users/kakao/Library/Developer/Xcode/DerivedData/GithubActionTest-gkqmxobtppqtapbinoqivdbgdpnu/Logs/Test/Test-GithubActionTest-2020.07.15_13-13-56-+0900.xcresult

 

인식할 수 없는 file-format이라고 나옵니다,,,!! 

 

 

WWDC 보니까 이런식으로 간편하게 리포트를 출력할 수 있던데,

xcode11부터 xccovreport가 아니라 xcresult가 생기도록 빌드시스템이 바뀌었다..?!?! (아닐수 있어요,,,) 라는 말이 있더라구요

xcrun xccov view --json GithubActionTest.xccovreport

 

 

그리고 이렇게 돌려보기도 했는데, xcresulttool 이라는 것을 사용해서...!! 

xcrun xcresulttool get --format json --path /Users/kakao/Library/Developer/Xcode/DerivedData/GithubActionTest-gkqmxobtppqtapbinoqivdbgdpnu/Logs/Test/Test-GithubActionTest-2020.07.15_14-21-15-+0900.xcresult

 

그러면 이런식으로 json이 나오는데, 휴먼리더블하지 않고 이게 뭘말하는 건지 잘모르겠네요ㅠㅠ

 





[3] xcpretty를 이용하기

 

우선 xcpretty를 설치해주세요

sudo gem install xcpretty

 

junit 또는 html로 report를 만들겠다고 해줄 수 있습니다.

 

1) junit으로 보기 

 

xcodebuild test -workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace -scheme 'GithubActionTest' -destination 'platform=iOS Simulator,name=iPad Pro (9.7-inch)' -enableCodeCoverage YES | xcpretty --report junit

 

 

2) html로 보기

 

xcodebuild test -workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace -scheme 'GithubActionTest' -destination 'platform=iOS Simulator,name=iPad Pro (9.7-inch)' -enableCodeCoverage YESxcpretty --report html

 

 

그러면 터미널에 이렇게 뜨고

 

 

 

 

User/사용자이름/Build/reports 디렉토리에 이렇게 파일이 생깁니다. 

 

 

 

 

tests.html을 열면 이런 화면을 볼 수 있습니다.

 

 

 

 

[4] slather를 이용하기

우선 slather 를 설치해주세요

sudo gem install slather

 

이렇게 돌리면 터미널에서 테스트 커버리지를 볼 수 있습니다.

slather coverage -s --scheme 'GithubActionTest' --workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace ~/Documents/GithubActionTest/GithubActionTest.xcodeproj

 

 

 

이렇게 돌리면 html을 만들어줍니다.

slather coverage --html --scheme 'GithubActionTest'  --workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace ~/Documents/GithubActionTest/GithubActionTest.xcodeproj

 

User/사용자이름/html 디렉토리에 파일을 생성해줍니다.

 

 

 

 

근데 output-directory를 설정해서 디렉토리를 바꿔줄 수 있습니다.

 

slather coverage --html --output-directory ~/Documents/GithubActionTest/reports --scheme 'GithubActionTest' --workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace ~/Documents/GithubActionTest/GithubActionTest.xcodeproj

 

 

이렇게 돌리면 터미널에서 친절하게 어디에 만들어졌는지 알려주고 

 

 

원하는 디렉토리에 생성됩니다

 

 

 

 

 

 

reports에 들어가서 index.html 을 열어보면 이렇게 나오고

 

 

AppDelegate 눌러서 들어가보면 이렇게

 

viewController 눌러서 들어가보면 이렇게 나오더라구요

 

초록색 블럭은 테스트로 커버가 된거 

빨간색 블럭은 테스트로 커버가 안된거 말하는 것 같아요

 

 

 

그리고 --show를 추가해서 돌리면 자동으로 만들어진 html파일을 열어줍니다 👍 (브라우저를 열어줍니다)

 

slather coverage --html --output-directory ~/Documents/GithubActionTest/reports  --show  --scheme 'GithubActionTest'  --workspace ~/Documents/GithubActionTest/GithubActionTest.xcworkspace ~/Documents/GithubActionTest/GithubActionTest.xcodeproj

 

 

 

[ 더보기 ]

 

slather 관련 발표자료 첨부-!!

www.slideshare.net/allanh0526/how-to-generate-code-coverage-reports-in-xcode-with-slather

 

How to generate code coverage reports in xcode with slather

How to Generate Code Coverage Reports in Xcode Allan Shih JULY 28TH, 2017

www.slideshare.net

 

반응형
댓글