machx / mocknetworking Goto Github PK
View Code? Open in Web Editor NEWApply URLProtocol to XCTests for Mock Networking API's
License: Apache License 2.0
Apply URLProtocol to XCTests for Mock Networking API's
License: Apache License 2.0
HTTPURLResponse doesn't encapsulate data or error and thus need to get that working
There are a couple types now of registration methods and I just want to make sure they are consistent and both provide access to the same http information
Need to verify that the headers setup in the mock response are actually returned.
Feels out of place in the same file as the protocol subclass
make sure you get this captured and tested correctly
URLPropertyStore sounds too official and doesn't sound like something from this package. I'd like to find a name that sounds more like it fits in with the expected naming style from this project.
Currently MockResponse is a collection of variables for things in HTTPURLResponse, etc. It should instead just compose together HTTPURLResponse and types in Foundation Networking.
Make sure it covers the response
need to add some sort of periodic reminder to test the package with new xcode versions
Implement something to delay mock networking responses
Implement a remove individual response for a specific url
URLResponse considers fields that MockNetworking doesn't care about such as mime type in the equality comparison. For unit test purposes only a better equality method/assertion should be made using 1 of 2 methods
Need to setup basic information for the project like
Currently the Readme shows an example of how to use MockNetworking with a API that I wouldn't use as much right now. This should be refactored to use the correct api type
the code sample with the input has a weird code indentation that should be fixed
Currently there is an API
public override func stopLoading() {
//
}
this should probably operate like NSOperation's cancel where you make a private variable and then just check it during the course of the load logic
Need to establish a documentation format and implement it where it should be implemented
I believe the latest unit tests i'm developing right now actually went out on the network where I thought it wouldn't.
AC
In the test
func testHTTPResponse() throws {
let url = try XCTUnwrap(URL(string: "https://wwww.apple.com"))
let response = try XCTUnwrap(HTTPURLResponse(url: url,
statusCode: 200,
httpVersion: HTTPURLResponse.HTTP_1_1,
headerFields: ["thing180":"thing2"]))
MockURLProtocol.register(response: response, for: url)
defer {
MockURLProtocol.unregister()
}
var receivedResponse: URLResponse?
let expectation = XCTestExpectation()
URLSession.sessionWith(.ephemeral).downloadTask(with: url) { (url, response, error) in
receivedResponse = response
expectation.fulfill()
}.resume()
wait(for: [expectation], timeout: 5.0)
XCTAssertNotNil(receivedResponse)
guard let receivedHTTPResponse = receivedResponse as? HTTPURLResponse else {
XCTFail("Could not convert Response to HTTPURLResponse type")
return
}
XCTAssertEqual(response.url, receivedHTTPResponse.url)
XCTAssertEqual(response.statusCode, receivedHTTPResponse.statusCode)
XCTAssertEqual(response.allStringHTTPHeaders(), receivedHTTPResponse.allStringHTTPHeaders())
}
if you straight ask for the 2 http responses being equal, you will get a negative response back. I suspect that the 2nd response (having gone through URLProtocol) has more fields in it than the one we supplied it to begin with. Should quickly evaluate this and see if a better equality method can be made for the unit test.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.