-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved Code Coverage #10
Conversation
Tests/BackendServiceTests.swift
Outdated
@@ -82,6 +82,11 @@ class BackendServiceTests: XCTestCase { | |||
XCTAssertEqual(mockNetworkService.cancelAllTasksCallCount, 1) | |||
} | |||
|
|||
func test_BackendServiceError_Equatable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this method necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, removing
Tests/NetworkRequestTests.swift
Outdated
@@ -104,4 +104,73 @@ class NetworkRequestTests: XCTestCase { | |||
XCTAssertEqual(urlRequest.cachePolicy, cachePolicy, file: file, line: line) | |||
XCTAssertEqual(urlRequest.timeoutInterval, timeout, file: file, line: line) | |||
} | |||
|
|||
// func test_NetworkRequestQueryParameterEncodingStrategy_EncodeUrlQueryAllowedCharacterSet() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to remove commented out code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
Tests/NetworkServiceTests.swift
Outdated
|
||
let _ = NetworkService(session: URLSession.shared, networkActivityIndicatable: MockNetworkActivityIndicator()) | ||
|
||
XCTAssert(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably test that the object created is not nil
Tests/NetworkServiceTests.swift
Outdated
func test_NetworkServiceHelper_InvalidHTTPResponsErrorUnknownError() { | ||
let _ = NetworkServiceHelper.networkServiceFailure(for: NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, userInfo: nil)) | ||
|
||
XCTAssert(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, should probably test that the object is not nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a check for the error
Tests/BackendServiceTests.swift
Outdated
|
||
let _ = AnyError(BackendServiceError.networkError(.unknownError, nil)) | ||
|
||
XCTAssert(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should test that the object created is not nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method doesn't return an optional so it either works or it doesn't. I can add a check for nil but it will throw a warning that it will never be nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I'm not super familiar with how this works, is there a property or something that you can test that got set properly, due to initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding a check for the errror
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few style nit picks, but those can be cleaned up when SwiftLint is re-enabled. Looks good to me.
@@ -87,6 +87,6 @@ extension BackendServiceError: Equatable { | |||
|
|||
extension AnyError: BackendServiceErrorInitializable { | |||
public init(_ backendServiceError: BackendServiceError) { | |||
self.init(backendServiceError) | |||
self.init( backendServiceError as Error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit picking here - but can we remove the leading space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/BackendServiceTests.swift
Outdated
func test_BackendServiceProtocol_Execute() { | ||
let mock = MockBackendService() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line of spacing here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/BackendServiceTests.swift
Outdated
|
||
XCTAssert(true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, very good. Thank you for bringing our code coverage > 90%! Just some minor changes, mainly around naming to keep things consistent with the rest of the tests.
Tests/HTTPTest.swift
Outdated
HTTP.HeaderKey.userAgent: "User-Agent" | ||
] | ||
|
||
items.forEach { (arg) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stylistic concern. Swift allows for tuples as the parameters passed into a closure so there shouldn't be a need for the extra let
below.
items.forEach { (key, value) in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/HTTPTest.swift
Outdated
] | ||
|
||
|
||
items.forEach { (arg) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/HTTPTest.swift
Outdated
XCTAssert(dataString == content) | ||
} | ||
|
||
func test_HTTPStatus_InitWithCode200() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to consider changing up the naming of some of these tests. This one pretty much makes sense, but might be able to be improved with something like:
func test_HTTPResponseInitWithCode200_ProducesStatusSuccessOK() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/HTTPTest.swift
Outdated
let response = HTTP.Response(code: 200, data: nil) | ||
switch response.status { | ||
case .success(let status): | ||
XCTAssert(status.rawValue == 200) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be more beneficial to be asserting on the enum case itself, to make sure the semantic meaning to the programmer is correct rather than just the underlying value. This will allow for some cleanup as well.
let response = HTTP.Response(code: 200, data: nil)
XCTAssertTrue(response.status == .success(.ok))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/HTTPTest.swift
Outdated
} | ||
} | ||
|
||
func test_HTTPStatus_InitWithCode299() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming tweaks could apply to the rest of these as well.
func test_HTTPResponseInitWithCode299_ProducesStatusSuccessUnknown() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/NetworkRequestTests.swift
Outdated
var body: Data? | ||
} | ||
|
||
func test_NetworkRequest_GetCachePolicy() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might tweak the name of these slightly as well since you're really testing that a NetworkRequest
created without an explicit cache policy and timeout return the default cache policy and timeout, right?
func test_NetworkRequestWithoutExplicitCachePolicyAndTimeout_ReturnsDefaultCachePolicyAndTimeout()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/NetworkRequestTests.swift
Outdated
XCTAssert(true) | ||
} | ||
|
||
struct CachePolicyAndTimeOutRequest: NetworkRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reorganize these structs and tests so that we have the structs at the top and the rest of the tests above the private
methods above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@testable import Hyperspace | ||
|
||
class MockNetworkService2: NetworkService { | ||
var setup = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make things more clear at the call site, you may want to consider modifying the name of this variable:
private(set) var initWithSessionNetworkActivityControllerWasCalled = false
Another option would be to take a somewhat less explicit name (that still gets the point across):
private(set) var defaultInitWasCalled = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
import Foundation | ||
@testable import Hyperspace | ||
|
||
class MockNetworkService2: NetworkService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a personal preference, but to me numbering the class doesn't feel right. What about a name like NetworkServiceMockSubclass
(or some variation of that)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Tests/NetworkSessionTest.swift
Outdated
|
||
let networkSession: NetworkSession = URLSession.shared | ||
let networkSessionDataTask: NetworkSessionDataTask = networkSession.dataTask(with: defaultRequest, completionHandler: { (data, response, error) in | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but I think it's a little more concise to just put the closure/function suffix on the same line since there's not actually any implementation. I think you can ignore the parameters passed into the closure as well (with an _
).
let networkSessionDataTask: NetworkSessionDataTask = networkSession.dataTask(with: defaultRequest, completionHandler: { _ in })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I worked on getting code coverage above 90%. Let me know any suggestions or fixes.