Skip to content

Commit

Permalink
Add testObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisLys committed Nov 18, 2024
1 parent e8df855 commit 265099f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
4 changes: 4 additions & 0 deletions SwiftRadio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
B05F1B292CC79F26007D10D5 /* SafariPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B05F1B282CC79F26007D10D5 /* SafariPage.swift */; };
B0CEAC2F2CDE76810090D6A6 /* AccessibilityIDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0CEAC2E2CDE76810090D6A6 /* AccessibilityIDs.swift */; };
B0CEAC302CDE7E770090D6A6 /* AccessibilityIDs.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0CEAC2E2CDE76810090D6A6 /* AccessibilityIDs.swift */; };
B0E8C5642CE9D2F20044D220 /* TestObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0E8C5632CE9D2F20044D220 /* TestObserver.swift */; };
CAA8FDB52000614600050F77 /* RadioPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA8FDB42000614600050F77 /* RadioPlayer.swift */; };
CF72ACE721F7155200461EED /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CF72ACE621F714D000461EED /* Main.storyboard */; };
DAEBB1E525161E5B0065ECF0 /* MainPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAEBB1E425161E5B0065ECF0 /* MainPage.swift */; };
Expand Down Expand Up @@ -166,6 +167,7 @@
B05F1B282CC79F26007D10D5 /* SafariPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariPage.swift; sourceTree = "<group>"; };
B0CEAC232CD7DF810090D6A6 /* SwiftRadioTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftRadioTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B0CEAC2E2CDE76810090D6A6 /* AccessibilityIDs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityIDs.swift; sourceTree = "<group>"; };
B0E8C5632CE9D2F20044D220 /* TestObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestObserver.swift; sourceTree = "<group>"; };
CAA8FDB42000614600050F77 /* RadioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioPlayer.swift; sourceTree = "<group>"; };
CF72ACE621F714D000461EED /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
DAEBB1E425161E5B0065ECF0 /* MainPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainPage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -424,6 +426,7 @@
DAEBB2022517421E0065ECF0 /* StationInfoTest.swift */,
DAEBB2042517491B0065ECF0 /* AppInfoTest.swift */,
DAEBB1FD251633AB0065ECF0 /* SmokeTest.swift */,
B0E8C5632CE9D2F20044D220 /* TestObserver.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -603,6 +606,7 @@
DAEBB1F2251627690065ECF0 /* AppInfoPage.swift in Sources */,
DAEBB1E525161E5B0065ECF0 /* MainPage.swift in Sources */,
DAEBB2032517421E0065ECF0 /* StationInfoTest.swift in Sources */,
B0E8C5642CE9D2F20044D220 /* TestObserver.swift in Sources */,
B0CEAC302CDE7E770090D6A6 /* AccessibilityIDs.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
16 changes: 0 additions & 16 deletions SwiftRadioUITests/Extensions/XCTest+Allure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,5 @@ public extension XCTest {
}
return self
}

@discardableResult
func before(_ name: String, step: () -> Void) -> XCTest {
XCTContext.runActivity(named: "befores: " + name) { _ in
step()
}
return self
}

@discardableResult
func after(_ name: String, step: () -> Void) -> XCTest {
XCTContext.runActivity(named: "afters: " + name) { _ in
step()
}
return self
}
}

2 changes: 1 addition & 1 deletion SwiftRadioUITests/Extensions/XCUIElement+Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension XCUIElement {
line: UInt = #line
) {
wait(
for: .exists,
for: .hittable,
time: timeout,
file: file,
line: line
Expand Down
2 changes: 2 additions & 0 deletions SwiftRadioUITests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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>NSPrincipalClass</key>
<string>$(PRODUCT_NAME).TestObserver</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down
39 changes: 38 additions & 1 deletion SwiftRadioUITests/Tests/TestObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,41 @@
// Copyright © 2024 matthewfecher.com. All rights reserved.
//

import Foundation
import XCTest

class TestObserver: NSObject, XCTestObservation {

override init() {
super.init()
XCTestObservationCenter.shared.addTestObserver(self)
}

func testBundleWillStart(_ testBundle: Bundle) {
print("Начало выполнения всех тестов.")
}

func testSuiteWillStart(_ testSuite: XCTestSuite) {
print("Начало выполнения тестов в секции: \(testSuite.name).")
}

func testCaseWillStart(_ testCase: XCTestCase) {
print("Тест начнётся: \(testCase.name)")
}

func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
print("Тест \(testCase.name) упал с ошибкой: \(description) в \(filePath ?? "неизвестно"), строка \(lineNumber).")
}

func testCaseDidFinish(_ testCase: XCTestCase) {
print("Тест завершился: \(testCase.name)")
}

func testSuiteDidFinish(_ testSuite: XCTestSuite) {
print("Набор тестов в секции \(testSuite.name) завершился.")
}

func testBundleDidFinish(_ testBundle: Bundle) {
print("Все тесты завершены.")
XCTestObservationCenter.shared.removeTestObserver(self)
}
}

0 comments on commit 265099f

Please sign in to comment.