Skip to content

Commit

Permalink
Rewrite a test case due to WordPressComRestApiError not longer confor…
Browse files Browse the repository at this point in the history
…m to Error
  • Loading branch information
crazytonyli committed Jan 18, 2024
1 parent d97d4e2 commit bedee4d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions WordPressKitTests/WordPressComRestApiTests+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ class WordPressComRestApiErrorTests: XCTestCase {

func testNSErrorBridging() {
for error in WordPressComRestApiErrorCode.allCases {
let oldNSError = error as NSError

let apiError = WordPressAPIError.endpointError(WordPressComRestApiEndpointError(code: error))
let newNSError = apiError as NSError

XCTAssertEqual(oldNSError.domain, "WordPressKit.WordPressComRestApiError")
XCTAssertEqual(oldNSError.domain, newNSError.domain)

XCTAssertEqual(oldNSError.code, error.rawValue)
XCTAssertEqual(oldNSError.code, newNSError.code)
XCTAssertEqual(newNSError.domain, "WordPressKit.WordPressComRestApiError")
XCTAssertEqual(newNSError.code, error.rawValue)
}
}

Expand Down

2 comments on commit bedee4d

@mokagio
Copy link
Contributor

Choose a reason for hiding this comment

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

Love to see this test changing within the scope of the PR itself.

I'm biased, but to me it shows the usefulness of unit tests as a development-guiding tool.

@crazytonyli
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, I was kind of on the opposite side: unit tests should not be updated during a refactor, except syntax changes.

This is pretty philosophical, but here is my thinking. Given the source code (WordPressComRestApi in this case) has good test coverage, when there are large refactor on the source code, but minimal (or none) changes on the related unit tests, that means the refactor is in a good state, because it didn't break any existing unit tests. That's why I created some small PRs to add unit tests before this large refactor, to increase the test coverage.

Please sign in to comment.