Skip to content

Commit

Permalink
Merge pull request #330 from boostcampwm-2021/test/RequestFactoryTests
Browse files Browse the repository at this point in the history
[테스트] RequestFactoryTests 작성
  • Loading branch information
Modyhoon authored Dec 2, 2021
2 parents 8546bf7 + 2e38048 commit a27e93f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
2 changes: 2 additions & 0 deletions BBus/BBus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
87038A90273C11630078EAE3 /* GetStationsByRouteListFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A8F273C11630078EAE3 /* GetStationsByRouteListFetcher.swift */; };
87038A92273C12320078EAE3 /* GetBusPosByRtidFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A91273C12320078EAE3 /* GetBusPosByRtidFetcher.swift */; };
87038A94273C12E20078EAE3 /* GetStationByUidItemFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87038A93273C12E20078EAE3 /* GetStationByUidItemFetcher.swift */; };
87115EFA27564D0F00601770 /* RequestFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A5182A527550988001EA530 /* RequestFactory.swift */; };
87115F172756758800601770 /* GetArrInfoByRouteListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87115F162756758800601770 /* GetArrInfoByRouteListUseCase.swift */; };
87115F19275675B900601770 /* GetStationsByRouteListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87115F18275675B900601770 /* GetStationsByRouteListUseCase.swift */; };
87115F1B275675E200601770 /* GetBusPosByRtidUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87115F1A275675E200601770 /* GetBusPosByRtidUseCase.swift */; };
Expand Down Expand Up @@ -1710,6 +1711,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
87115EFA27564D0F00601770 /* RequestFactory.swift in Sources */,
4AF1E08F2756264600DE51C8 /* RequestFactoryTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
55 changes: 45 additions & 10 deletions BBus/RequestFactoryTests/RequestFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,59 @@ import XCTest

class RequestFactoryTests: XCTestCase {

private var requestFactory: Requestable?

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()
self.requestFactory = RequestFactory()
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
self.requestFactory = nil
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
func test_request_파라미터2개_생성_일치() throws {
// given
let mockUrl = "http://ws.bus.go.kr/testUrl"
let mockAccessKey = "uAtMsUVNMLIM%2FM9%3D%3D"
let mockParam = ["stId": "10001", "busRouteId": "1001001"]
let answer1 = URL(string: "http://ws.bus.go.kr/testUrl?stId=10001&busRouteId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer2 = URL(string: "http://ws.bus.go.kr/testUrl?busRouteId=1001001&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answers = [answer1, answer2]

// when
guard let requestResult = self.requestFactory?.request(url: mockUrl, accessKey: mockAccessKey, params: mockParam) else {
XCTFail("request result is nil")
return
}

// then
XCTAssertNotNil(requestResult)
XCTAssertTrue(answers.contains(requestResult.url))
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
measure {
// Put the code you want to measure the time of here.
func test_request_파라미터3개_생성_일치() throws {
//given
let mockUrl = "http://www.BBus.test"
let mockAccessKey = "uAtMsUVNMLIM%2FM9%3D%3D"
let mockParam = ["stId": "10001", "routeId": "1001001", "ord": "1"]
let answer1 = URL(string: "http://www.BBus.test?stId=10001&routeId=1001001&ord=1&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer2 = URL(string: "http://www.BBus.test?routeId=1001001&stId=10001&ord=1&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer3 = URL(string: "http://www.BBus.test?ord=1&routeId=1001001&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer4 = URL(string: "http://www.BBus.test?stId=10001&ord=1&routeId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer5 = URL(string: "http://www.BBus.test?routeId=1001001&ord=1&stId=10001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answer6 = URL(string: "http://www.BBus.test?ord=1&stId=10001&routeId=1001001&serviceKey=uAtMsUVNMLIM%2FM9%3D%3D")
let answers = [answer1, answer2, answer3, answer4, answer5, answer6]

// when
guard let requestResult = self.requestFactory?.request(url: mockUrl, accessKey: mockAccessKey, params: mockParam) else {
XCTFail("request result is nil")
return
}

// then
XCTAssertNotNil(requestResult)
XCTAssertTrue(answers.contains(requestResult.url))
}

}

0 comments on commit a27e93f

Please sign in to comment.