관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - swift] 3. xcodebuild로 테스트 돌리기 - xcresult 파일 변환하여 분석하기 (xcrun xcresulttool, xcpretty, junit) 본문

iOS 응용 (swift)

[iOS - swift] 3. xcodebuild로 테스트 돌리기 - xcresult 파일 변환하여 분석하기 (xcrun xcresulttool, xcpretty, junit)

jake-kim 2024. 8. 23. 01:29

1. xcodebuild로 테스트 돌리기 - 개념 (xcodebuild, unit test, ui test)

2. xcodebuild로 테스트 돌리기 - 결과 얻어오기 (xcresult)

3. xcodebuild로 테스트 돌리기 - xcresult 파일 변환하여 분석하기 (xcrun xcresulttool, xcpretty, junit)

1. xcresulttool를 사용하여 변환: xcresult -> json

  • .xcresult는 범용적인 포멧이 아니므로 json으로 변환을 하면 ci와 같은 여러곳에서 사용이 가능
    • xcrun xcresulttool을 사용
xcrun xcresulttool get --path "TestResults.xcresult" --format json

  • json으로 보면 key-value 쌍으로 있고 익숙한 포멧이지만 직관적으로 보기가 힘든 단점이 존재
    • 아래에서 살펴볼 xcpretty나 slather를 사용하면 더욱 편하게 볼 수 있음

2. xcpretty를 사용하여 변환

  • xcpretty 설치
sudo gem install xcpretty
  • xcbuild 옵션에 xcpretty를 파이프라인으로 추가
xcodebuild test \
-scheme App \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-resultBundlePath ./TestResults.xcresult \
| xcpretty -r junit --output ./report.xml
  • report.xml 파일 생성 이 파일은 junit 포멧

* junit 포멧이란? JUnit 포맷은 소프트웨어 테스트 결과를 XML 형식으로 표현하는 표준 형식 (아래와 같은 형태)

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="MyTestSuite" tests="3" failures="1" errors="0" skipped="1" time="0.012">
        <testcase classname="MyClass" name="testOne" time="0.004"/>
        <testcase classname="MyClass" name="testTwo" time="0.003">
            <failure message="failure message" type="AssertionError">Expected true but got false</failure>
        </testcase>
        <testcase classname="MyClass" name="testThree" time="0.005">
            <skipped/>
        </testcase>
    </testsuite>
</testsuites>
  • report.xml 파일을 오픈하면 아래와 같은 정보 확인이 가능
    • 테스트 수, failures 수를 보여줌

report.xml

  • junit 형태도 있지만, html형태도 가능
    • xcpretty 옵션 중 junit대신에 html을 작성하고 확장자명도 report.xml대신 report.html로 작성
xcodebuild test \                                                           
-scheme App \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-resultBundlePath ./TestResults.xcresult \
| xcpretty -r html --output ./report.html
  • 결과

report.xml

* 참고

- https://github.com/SlatherOrg/slather

Comments