Last active
May 27, 2022 08:35
-
-
Save MultiColourPixel/a5dce5dadb284ad7f2b3320937c3a085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import XCTest | |
| extension XCTestCase { | |
| private class TestBundle { } | |
| func deserializedObject<T: Decodable>(resourceName: String) throws -> T { | |
| let bundle = Bundle(for: TestBundle.self) | |
| let url = try XCTUnwrap(bundle.url(forResource: resourceName, withExtension: "json")) | |
| let data = try Data(contentsOf: url) | |
| return try JSONDecoder().decode(T.self, from: data) | |
| } | |
| func loadJSON(resourceName: String) throws -> Any { | |
| let bundle = Bundle(for: TestBundle.self) | |
| let url = try XCTUnwrap(bundle.url(forResource: resourceName, withExtension: "json")) | |
| let data = try Data(contentsOf: url) | |
| return try JSONSerialization.jsonObject(with: data) | |
| } | |
| func loadData(resourceName: String) throws -> Data { | |
| let bundle = Bundle(for: TestBundle.self) | |
| let url = try XCTUnwrap(bundle.url(forResource: resourceName, withExtension: "json")) | |
| return try Data(contentsOf: url) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment