I have some tests written using XCTestCase
classes and I want to calculate code coverage. For the regular test it is shown nicely in my bot, but for UI Tests is always 0%.
The simplest test:
import XCTest class FAQUITests: XCTestCase { let app = XCUIApplication() override func setUp() { super.setUp() app.launch() } func openFaqView() { app.navigationBars["NavigationBar"].buttons["FAQ"].tap() } func testFaq() { openFaqView() app.tables.cells.elementBoundByIndex(0).tap() } }
And this surely should show some test coverage but it's not. I set in my bot code coverage enabled:
And result:
Still 0%.
Xcode 7.2 (7C68)
EDIT: Example Project : https://[email protected]/Kettu/so_34718699.git
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
Calculating test coverage is actually fairly easy. You can simply take the number of lines that are covered by a test (any kind of test, across your whole testing strategy) and divide by the total number of lines in your application.
To view the coverage reports: Select the Report Navigator in the navigator pane on the left (⌘8) Select the latest Test run in the navigator pane. Select the Coverage tab in the editor.
Check if the "Gather coverage data" is active in the Test Scheme.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With