Skip to content

Commit

Permalink
fixed case when launch can not be finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Komarov committed Nov 9, 2017
1 parent 4eb4c5b commit b22d246
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions RPAgentSwiftXCTest.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = '9.0'
s.source_files = 'RPAgentSwiftXCTest/**/*'

s.dependency 'Alamofire', '~> 4.5.0'
s.dependency 'AlamofireObjectMapper', '~> 4.1.0'
s.dependency 'Alamofire', '~> 4.5.1'
s.dependency 'AlamofireObjectMapper', '~> 5.0.0'

s.weak_framework = "XCTest"
s.pod_target_xcconfig = {
Expand Down
4 changes: 0 additions & 4 deletions RPAgentSwiftXCTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
368751B11F5867140021B74D /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 368751B01F5867140021B74D /* Podfile */; };
368751B91F5867200021B74D /* EndPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368751B21F5867200021B74D /* EndPoint.swift */; };
368751BA1F5867200021B74D /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368751B31F5867200021B74D /* HTTPClient.swift */; };
368751BB1F5867200021B74D /* RPConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 368751B41F5867200021B74D /* RPConstants.swift */; };
Expand All @@ -25,7 +24,6 @@
1D1E0E6351F9DD7719F920F3 /* Pods-RPAgentSwiftXCTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RPAgentSwiftXCTest.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RPAgentSwiftXCTest/Pods-RPAgentSwiftXCTest.debug.xcconfig"; sourceTree = "<group>"; };
368751A51F5866CA0021B74D /* RPAgentSwiftXCTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RPAgentSwiftXCTest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
368751A91F5866CA0021B74D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
368751B01F5867140021B74D /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
368751B21F5867200021B74D /* EndPoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EndPoint.swift; sourceTree = "<group>"; };
368751B31F5867200021B74D /* HTTPClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = "<group>"; };
368751B41F5867200021B74D /* RPConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RPConstants.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -58,7 +56,6 @@
368751E41F596E990021B74D /* LICENSE */,
368751E21F596BC70021B74D /* RPAgentSwiftXCTest.podspec */,
368751E01F5964AA0021B74D /* README.md */,
368751B01F5867140021B74D /* Podfile */,
368751A71F5866CA0021B74D /* RPAgentSwiftXCTest */,
368751A61F5866CA0021B74D /* Products */,
7D5FA0B8C6D6D72556763B1E /* Pods */,
Expand Down Expand Up @@ -180,7 +177,6 @@
files = (
368751E11F5964AA0021B74D /* README.md in Resources */,
368751E51F596E990021B74D /* LICENSE in Resources */,
368751B11F5867140021B74D /* Podfile in Resources */,
368751E31F596BC70021B74D /* RPAgentSwiftXCTest.podspec in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
33 changes: 22 additions & 11 deletions RPAgentSwiftXCTest/RPListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest

public class RPListener: NSObject, XCTestObservation {

let serviceRP = RPService()
var serviceRP: RPService?
let queue = DispatchQueue(label: "com.oxagile.report.portal", qos: .utility)
var bundleProperties: [String: Any]!

Expand All @@ -21,21 +21,27 @@ public class RPListener: NSObject, XCTestObservation {
}

public func testBundleWillStart(_ testBundle: Bundle) {
guard let path = testBundle.path(forResource: "Info", ofType: "plist") else { return }
guard let path = testBundle.path(forResource: "Info", ofType: "plist") else {return }
bundleProperties = NSDictionary(contentsOfFile: path) as? [String: Any]
guard bundleProperties?["PushTestDataToReportPortal"] as! Bool else {
XCTestObservationCenter.shared.removeTestObserver(self)
guard let pushData = bundleProperties["PushTestDataToReportPortal"] as? Bool else {
print("Configure properties for report portal in the Info.plist")
return
}
guard pushData else {
print("Set 'YES' for 'PushTestDataToReportPortal' property in Info.plist if you want to put data to report portal")
return
}
serviceRP = RPService()
queue.async {
self.serviceRP.startLaunch(self.bundleProperties)
self.serviceRP!.startLaunch(self.bundleProperties)
}
}

public func testSuiteWillStart(_ testSuite: XCTestSuite) {
guard let service = serviceRP else { return }
if !testSuite.name.contains("Selected tests"), !testSuite.name.contains(".xctest") {
queue.async {
self.serviceRP.startTestCase(testSuite)
service.startTestCase(testSuite)
}
}
}
Expand All @@ -45,34 +51,39 @@ public class RPListener: NSObject, XCTestObservation {
}

public func testCaseWillStart(_ testCase: XCTestCase) {
guard let service = serviceRP else { return }
queue.async {
self.serviceRP.startTest(testCase)
service.startTest(testCase)
}
}

public func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
guard let service = serviceRP else { return }
queue.async {
self.serviceRP.reportError(message: "Test '\(String(describing: testCase.name)))' failed on line \(lineNumber), \(description)")
service.reportError(message: "Test '\(String(describing: testCase.name)))' failed on line \(lineNumber), \(description)")
}
}

public func testCaseDidFinish(_ testCase: XCTestCase) {
guard let service = serviceRP else { return }
queue.async {
self.serviceRP.finishTest(testCase)
service.finishTest(testCase)
}
}

public func testSuiteDidFinish(_ testSuite: XCTestSuite) {
guard let service = serviceRP else { return }
if !testSuite.name.contains("Selected tests"), !testSuite.name.contains(".xctest") {
queue.async {
self.serviceRP.finishTestCase()
service.finishTestCase()
}
}
}

public func testBundleDidFinish(_ testBundle: Bundle) {
guard let service = serviceRP else { return }
queue.sync() {
self.serviceRP.finishLaunch()
service.finishLaunch()
}
}
}

0 comments on commit b22d246

Please sign in to comment.