Code coverage result is not accurate to real coverage in Xcode 7

前端 未结 5 806
清歌不尽
清歌不尽 2021-02-02 12:18

I am running test cases in application with enabled code coverage data Xcode 7 Beta 2. But I am able to get only few files coverage data while my all test cases are running succ

5条回答
  •  天涯浪人
    2021-02-02 12:44

    IT WORKS.

    1. Since Apple released @testable keyword to import your project into test target, you don't have to add your files to both target anymore:

    1. So just remove every file from your test target:

    1. Wherever you need access to your file from your test target just import your target using: @testable import MyApp

    1. Do this for every file in your project.

    Then code coverage will be working fine.

    Read more from Swift 2 + Xcode 7: Unit Testing Access Made Easy!!!!

    If you need to know how to work with code coverage read How to use code coverage in Xcode 7?

    As @Gerd Castan mentioned earlier is: "So it appears to me that a tested method shows a coverage of 0 when there exists at least one target where this method is not tested."

    Solution is simple. Do not let compiler think that this file is included in more that one target, instead import your module using @testable keyword.

提交回复
热议问题