Skip to content
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

Merged
merged 6 commits into from
Feb 2, 2018
Merged

Conversation

Adamcbrz
Copy link

I worked on getting code coverage above 90%. Let me know any suggestions or fixes.
screen shot 2018-01-31 at 9 16 36 am

@@ -82,6 +82,11 @@ class BackendServiceTests: XCTestCase {
XCTAssertEqual(mockNetworkService.cancelAllTasksCallCount, 1)
}

func test_BackendServiceError_Equatable() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this method necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, removing

@@ -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() {
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing


let _ = NetworkService(session: URLSession.shared, networkActivityIndicatable: MockNetworkActivityIndicator())

XCTAssert(true)
Copy link
Contributor

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

func test_NetworkServiceHelper_InvalidHTTPResponsErrorUnknownError() {
let _ = NetworkServiceHelper.networkServiceFailure(for: NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, userInfo: nil))

XCTAssert(true)
Copy link
Contributor

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

Copy link
Author

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


let _ = AnyError(BackendServiceError.networkError(.unknownError, nil))

XCTAssert(true)
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

@wmcginty wmcginty left a 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)
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

func test_BackendServiceProtocol_Execute() {
let mock = MockBackendService()


Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


XCTAssert(true)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@tylermilner tylermilner left a 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.

HTTP.HeaderKey.userAgent: "User-Agent"
]

items.forEach { (arg) in
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

]


items.forEach { (arg) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

XCTAssert(dataString == content)
}

func test_HTTPStatus_InitWithCode200() {
Copy link
Contributor

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() {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let response = HTTP.Response(code: 200, data: nil)
switch response.status {
case .success(let status):
XCTAssert(status.rawValue == 200)
Copy link
Contributor

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))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}

func test_HTTPStatus_InitWithCode299() {
Copy link
Contributor

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() {

Copy link
Author

@Adamcbrz Adamcbrz Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

var body: Data?
}

func test_NetworkRequest_GetCachePolicy() {
Copy link
Contributor

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()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

XCTAssert(true)
}

struct CachePolicyAndTimeOutRequest: NetworkRequest {
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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

Copy link
Author

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 {
Copy link
Contributor

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)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


let networkSession: NetworkSession = URLSession.shared
let networkSessionDataTask: NetworkSessionDataTask = networkSession.dataTask(with: defaultRequest, completionHandler: { (data, response, error) in
})
Copy link
Contributor

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 })

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@tylermilner tylermilner merged commit a6a6ee8 into BottleRocketStudios:master Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants