WeTransfer / Mocker

Mock Alamofire and URLSession requests without touching your code implementation
MIT License
1.12k stars 96 forks source link

Testing functions having https request call using Mocker fail #131

Closed usmaanirfan closed 1 year ago

usmaanirfan commented 2 years ago

Writing unit test cases for functions using mock data where https url requests are made. After some success tests it stuck in waiting and finally fail because of time out. May be because number of threads are created around 265. Can someone suggest how to fix this. below is the test case how it is being used.

func testRefreshSuccess() { let mockExpectation = expectation(description: "Get detail mock should be called") let requestURL = BaseUrl + getAssetDetailAPI + testAssetId let mockDataUsage = FileReader.contentsOfFileInBundle("Details")! let mockUsage = Mock(url: URL(string: requestURL)!, dataType: .json, statusCode: 200, data: [.get: mockDataUsage]) mockUsage.register()

    viewModel?.refresh()
    viewModel?.isDataLoadig.bindAndFire { [weak self] (isDataLoadig : Bool) in
        if isDataLoadig == false {
            XCTAssertNotNil(self?.viewModel?.details.value)
            XCTAssertEqual(self?.viewModel?.details.value?.assetId, self?.testAssetId)
            mockExpectation.fulfill()
        }
    }
    wait(for: [mockExpectation], timeout: Constants.timeout)
}
AvdLee commented 2 years ago

Are there any logs that hint you in a direction?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.