Skip to content

Commit

Permalink
[test] RxTest 기본 틀 작성 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
trumanfromkorea committed Jan 9, 2023
1 parent 5d05eaa commit 63605de
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 40 deletions.
38 changes: 34 additions & 4 deletions SpaceCapsule/SpaceCapsule.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
0D6CA337292216A300E02393 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CA336292216A300E02393 /* SceneDelegate.swift */; };
0D6CA33E292216A400E02393 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D6CA33D292216A400E02393 /* Assets.xcassets */; };
0D6CA341292216A400E02393 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0D6CA33F292216A400E02393 /* LaunchScreen.storyboard */; };
0D6CA34C292216A400E02393 /* SpaceCapsuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CA34B292216A400E02393 /* SpaceCapsuleTests.swift */; };
0D6CA34C292216A400E02393 /* BaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CA34B292216A400E02393 /* BaseTestCase.swift */; };
0D6CA356292216A400E02393 /* SpaceCapsuleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CA355292216A400E02393 /* SpaceCapsuleUITests.swift */; };
0D6CA358292216A400E02393 /* SpaceCapsuleUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CA357292216A400E02393 /* SpaceCapsuleUITestsLaunchTests.swift */; };
0D6CA366292218EB00E02393 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 0D6CA365292218EB00E02393 /* RxCocoa */; };
Expand All @@ -27,6 +27,9 @@
0D706139292C63140077787E /* DatePickerCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D706138292C63140077787E /* DatePickerCoordinator.swift */; };
0D70613E292CD24D0077787E /* FirebaseStorageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D70613D292CD24D0077787E /* FirebaseStorageManager.swift */; };
0D77D7C9292B5D490038D054 /* SelectButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D77D7C8292B5D490038D054 /* SelectButton.swift */; };
0D8D2D22296BFC9800DF713E /* RxTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D8D2D21296BFC9800DF713E /* RxTestCase.swift */; };
0D8D2D25296BFD5F00DF713E /* RxTest in Frameworks */ = {isa = PBXBuildFile; productRef = 0D8D2D24296BFD5F00DF713E /* RxTest */; };
0D8D2D27296C2F8A00DF713E /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 0D8D2D26296C2F8A00DF713E /* RxCocoa */; };
0D90DAEF29238B77000DCC84 /* CapsuleLocateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D90DAEE29238B77000DCC84 /* CapsuleLocateView.swift */; };
0D90DAF129238B85000DCC84 /* CapsuleLocateCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D90DAF029238B85000DCC84 /* CapsuleLocateCoordinator.swift */; };
0D90DAF329238B90000DCC84 /* CapsuleCloseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D90DAF229238B90000DCC84 /* CapsuleCloseCoordinator.swift */; };
Expand Down Expand Up @@ -210,13 +213,14 @@
0D6CA33D292216A400E02393 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
0D6CA340292216A400E02393 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
0D6CA342292216A400E02393 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0D6CA34B292216A400E02393 /* SpaceCapsuleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceCapsuleTests.swift; sourceTree = "<group>"; };
0D6CA34B292216A400E02393 /* BaseTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTestCase.swift; sourceTree = "<group>"; };
0D6CA355292216A400E02393 /* SpaceCapsuleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceCapsuleUITests.swift; sourceTree = "<group>"; };
0D6CA357292216A400E02393 /* SpaceCapsuleUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpaceCapsuleUITestsLaunchTests.swift; sourceTree = "<group>"; };
0D706136292C630D0077787E /* DatePickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerViewModel.swift; sourceTree = "<group>"; };
0D706138292C63140077787E /* DatePickerCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerCoordinator.swift; sourceTree = "<group>"; };
0D70613D292CD24D0077787E /* FirebaseStorageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseStorageManager.swift; sourceTree = "<group>"; };
0D77D7C8292B5D490038D054 /* SelectButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectButton.swift; sourceTree = "<group>"; };
0D8D2D21296BFC9800DF713E /* RxTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxTestCase.swift; sourceTree = "<group>"; };
0D90DAEE29238B77000DCC84 /* CapsuleLocateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleLocateView.swift; sourceTree = "<group>"; };
0D90DAF029238B85000DCC84 /* CapsuleLocateCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleLocateCoordinator.swift; sourceTree = "<group>"; };
0D90DAF229238B90000DCC84 /* CapsuleCloseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapsuleCloseCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -389,6 +393,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0D8D2D27296C2F8A00DF713E /* RxCocoa in Frameworks */,
0D8D2D25296BFD5F00DF713E /* RxTest in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -438,6 +444,7 @@
0DA72BDF2939F7D700DF6E69 /* SpaceCapsule.app */,
0DA72BE02939F7D700DF6E69 /* SpaceCapsuleTests.xctest */,
0DA72BE12939F7D700DF6E69 /* SpaceCapsuleUITests.xctest */,
0D8D2D23296BFD5F00DF713E /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -470,7 +477,8 @@
0D6CA34A292216A400E02393 /* SpaceCapsuleTests */ = {
isa = PBXGroup;
children = (
0D6CA34B292216A400E02393 /* SpaceCapsuleTests.swift */,
0D6CA34B292216A400E02393 /* BaseTestCase.swift */,
0D8D2D21296BFC9800DF713E /* RxTestCase.swift */,
);
path = SpaceCapsuleTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -505,6 +513,13 @@
path = Firebase;
sourceTree = "<group>";
};
0D8D2D23296BFD5F00DF713E /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
0D90DAF5292397BF000DCC84 /* Extensions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1006,6 +1021,10 @@
0D6CA349292216A400E02393 /* PBXTargetDependency */,
);
name = SpaceCapsuleTests;
packageProductDependencies = (
0D8D2D24296BFD5F00DF713E /* RxTest */,
0D8D2D26296C2F8A00DF713E /* RxCocoa */,
);
productName = SpaceCapsuleTests;
productReference = 0DA72BE02939F7D700DF6E69 /* SpaceCapsuleTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
Expand Down Expand Up @@ -1295,7 +1314,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0D6CA34C292216A400E02393 /* SpaceCapsuleTests.swift in Sources */,
0D6CA34C292216A400E02393 /* BaseTestCase.swift in Sources */,
0D8D2D22296BFC9800DF713E /* RxTestCase.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1703,6 +1723,16 @@
package = 0D6CA3692922197D00E02393 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = SnapKit;
};
0D8D2D24296BFD5F00DF713E /* RxTest */ = {
isa = XCSwiftPackageProductDependency;
package = 0D6CA364292218EB00E02393 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxTest;
};
0D8D2D26296C2F8A00DF713E /* RxCocoa */ = {
isa = XCSwiftPackageProductDependency;
package = 0D6CA364292218EB00E02393 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxCocoa;
};
0DBD20A529519E3500C74F4F /* KingReceiver */ = {
isa = XCSwiftPackageProductDependency;
package = 0DBD20A429519E3400C74F4F /* XCRemoteSwiftPackageReference "KingReceiver" */;
Expand Down
22 changes: 22 additions & 0 deletions SpaceCapsule/SpaceCapsuleTests/BaseTestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// BaseTestCase.swift
// BaseTestCase
//
// Created by 장재훈 on 2023/01/09.
//

import XCTest

class BaseTestCase: XCTestCase {
func given(_ task: () -> Void) {
task()
}

func when(_ task: () -> Void) {
task()
}

func then(_ task: () -> Void) {
task()
}
}
56 changes: 56 additions & 0 deletions SpaceCapsule/SpaceCapsuleTests/RxTestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// RxTestCase.swift
// SpaceCapsuleTests
//
// Created by 장재훈 on 2023/01/09.
//

import RxCocoa
import RxRelay
import RxSwift
import RxTest
import XCTest

class RxTestCase<T>: BaseTestCase {
var scheduler: TestScheduler!
var disposeBag: DisposeBag!
private var resultObserver: TestableObserver<T>!

var eventsToObserve: Observable<T> = .empty() {
didSet {
disposeBag = DisposeBag()
scheduler = TestScheduler(initialClock: 0)
resultObserver = scheduler.createObserver(T.self)

eventsToObserve
.bind(to: resultObserver)
.disposed(by: disposeBag)
}
}

func when(observing events: Observable<T>, _ task: () -> Void) {
eventsToObserve = events
task()
executeEvents()
}

func createEvents<U>(_ events: [Recorded<Event<U>>], to relay: PublishRelay<U>) {
scheduler
.createHotObservable(events)
.bind(to: relay)
.disposed(by: disposeBag)
}

func createEvents<U>(_ events: [Recorded<Event<U>>], to subject: PublishSubject<U>) {
scheduler
.createHotObservable(events)
.bind(to: subject)
.disposed(by: disposeBag)
}

func executeEvents(advanceTo futureTime: VirtualTimeScheduler<TestSchedulerVirtualTimeConverter>.VirtualTime = 10) {
scheduler.start()
scheduler.advanceTo(futureTime)
scheduler.stop()
}
}
36 changes: 0 additions & 36 deletions SpaceCapsule/SpaceCapsuleTests/SpaceCapsuleTests.swift

This file was deleted.

0 comments on commit 63605de

Please sign in to comment.