Skip to content

Commit

Permalink
Added tests (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllDmeat authored Dec 19, 2023
1 parent f311b1b commit 633fdd3
Show file tree
Hide file tree
Showing 42 changed files with 119 additions and 25 deletions.
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ let package = Package(
.init(stringLiteral: packageTestHelpersName)
],
resources: [
.process("Resources/AllTests.xcresult"),
.process("Resources/AllTests_coverage.xcresult"),
.process("Resources/E2ETests.xcresult")
.process("Resources/DBXCResultParser.xcresult")
]
),
]
Expand Down
27 changes: 27 additions & 0 deletions Sources/DBXCResultParserTestHelpers/CoverageDTO+TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// CoverageDTO+TestHelpers.swift
//
//
// Created by Aleksey Berezka on 19.12.2023.
//

import Foundation
@testable import DBXCResultParser

extension CoverageDTO {
public static func testMake(
buildProductPath: String = "",
coveredLines: Int = 0,
executableLines: Int = 0,
lineCoverage: Double = 0,
name: String = ""
) -> CoverageDTO {
self.init(
buildProductPath: buildProductPath,
coveredLines: coveredLines,
executableLines: executableLines,
lineCoverage: lineCoverage,
name: name
)
}
}
18 changes: 3 additions & 15 deletions Tests/DBXCResultParserTests/Constants+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ import XCTest
extension Constants {
static var resourcesPath: URL {
get throws {
try unitTestsReportPath.deletingLastPathComponent()
try testsReportPath.deletingLastPathComponent()
}
}

static var unitTestsReportPath: URL {
static var testsReportPath: URL {
get throws {
try path(filename: "AllTests", type: "xcresult")
}
}

static var unitTestsWithCoverageReportPath: URL {
get throws {
try path(filename: "AllTests_coverage", type: "xcresult")
}
}

static var e2eTestsReportPath: URL {
get throws {
try path(filename: "E2ETests", type: "xcresult")
try path(filename: "DBXCResultParser", type: "xcresult")
}
}

Expand Down
22 changes: 19 additions & 3 deletions Tests/DBXCResultParserTests/CoverageDTOTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Created by Yaroslav Bredikhin on 06.09.2022

import Foundation
import Foundation
import XCTest
@testable import DBXCResultParser
Expand All @@ -15,7 +14,24 @@ class CoverageDTOTests: XCTestCase {
try super.tearDownWithError()
}

func test_file_with_coverage() throws {
XCTAssertNoThrow(try Array<CoverageDTO>(from: Constants.unitTestsWithCoverageReportPath))
func test_coverageDtoParse() throws {
XCTAssertNoThrow(try Array<CoverageDTO>(from: Constants.testsReportPath))
}

func test_coverageDtoData() throws {
let result = try Array<CoverageDTO>(from: Constants.testsReportPath)
XCTAssertEqual(result.count, 3) // as targets count
let expectedResult = CoverageDTO.testMake(
coveredLines: 299,
executableLines: 582,
lineCoverage: 0.5137457044673539,
name: "DBXCResultParser"
)

let target = try XCTUnwrap(result.first { $0.name == expectedResult.name })

XCTAssertEqual(target.coveredLines, expectedResult.coveredLines)
XCTAssertEqual(target.executableLines, expectedResult.executableLines)
XCTAssertEqual(target.lineCoverage, expectedResult.lineCoverage)
}
}
35 changes: 35 additions & 0 deletions Tests/DBXCResultParserTests/DBXCReportModelTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Created by Yaroslav Bredikhin on 06.09.2022

import Foundation
import XCTest
@testable import DBXCResultParser

class DBXCReportModelTests: XCTestCase {

override func setUpWithError() throws {
try super.setUpWithError()
}

override func tearDownWithError() throws {
try super.tearDownWithError()
}

func test() throws {
let report = try DBXCReportModel(xcresultPath: Constants.testsReportPath)
XCTAssertEqual(report.modules.count, 1)

let module = try XCTUnwrap(report.modules.first)
XCTAssertEqual(module.name, "DBXCResultParserTests")
XCTAssertEqual(module.coverage?.coveredLines, 299)

let files = module.files.sorted { $0.name < $1.name }
XCTAssertEqual(files.count, 5)

let file = try XCTUnwrap(files.first)
XCTAssertEqual(file.name, "CoverageDTOTests")
XCTAssertEqual(file.repeatableTests.count, 1)

let test = try XCTUnwrap(file.repeatableTests.first)
XCTAssertEqual(test.name, "test_file_with_coverage()")
}
}
6 changes: 3 additions & 3 deletions Tests/DBXCResultParserTests/DetailedReportDTOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class DetailedReportDTOTests: XCTestCase {
}

func test_parseWithExplicitRefId() throws {
let overviewReport = try OverviewReportDTO(from: Constants.unitTestsReportPath)
XCTAssertNoThrow(try DetailedReportDTO(from: Constants.unitTestsReportPath, refId: overviewReport.testsRefId))
let overviewReport = try OverviewReportDTO(from: Constants.testsReportPath)
XCTAssertNoThrow(try DetailedReportDTO(from: Constants.testsReportPath, refId: overviewReport.testsRefId))
}

func test_parseWithImplicitRefId() throws {
XCTAssertNoThrow(try DetailedReportDTO(from: Constants.unitTestsReportPath))
XCTAssertNoThrow(try DetailedReportDTO(from: Constants.testsReportPath))
}
}
2 changes: 1 addition & 1 deletion Tests/DBXCResultParserTests/OverviewReportDTOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class OverviewReportDTOTests: XCTestCase {
}

func test() {
XCTAssertNoThrow(try OverviewReportDTO(from: Constants.unitTestsReportPath))
XCTAssertNoThrow(try OverviewReportDTO(from: Constants.testsReportPath))
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"testmanagerd.log","type":1}]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>dateCreated</key>
<date>2023-12-18T14:59:20Z</date>
<key>externalLocations</key>
<array/>
<key>rootId</key>
<dict>
<key>hash</key>
<string>0~w-cG65XA9aRf4hPf1EJMvmSuZrVZwHv5zzYQShp2XVXhZ6V13xEtVWs6uSWpwb1VFtlEwM6bATzJo6iF0f-zdA==</string>
</dict>
<key>storage</key>
<dict>
<key>backend</key>
<string>fileBacked2</string>
<key>compression</key>
<string>standard</string>
</dict>
<key>version</key>
<dict>
<key>major</key>
<integer>3</integer>
<key>minor</key>
<integer>44</integer>
</dict>
</dict>
</plist>

0 comments on commit 633fdd3

Please sign in to comment.