I am experiencing a strange behavior when using XCTest to check if an error is being thrown. I have a method called dispose() that can throw that looks like this:
func dispose() throws
I wrote a unit test in XCTest that looks like this:
func testDispose() {
do {
// sound is properly initialized during setUp()
try sound.dispose()
} catch {
XCTFail("Error thrown.")
}
}
The sole purpose of the test is to test if an error is thrown when disposing of a properly initialized object that is known to be in a valid state.
The test passes, but in the console I get the following output:
Test Case '-[LVGSwiftSystemSoundServices_Tests.SystemSoundTypeTests testDispose]' started.
System Sound Services Error: Unspecified error.
Message: An error occurred while disposing of the SystemSoundID.
Code: -1500
Test Case '-[LVGSwiftSystemSoundServices_Tests.SystemSoundTypeTests testDispose]' passed (0.015 seconds).
The lines that start with SystemSoundServices Error:... are the description of the error that would be thrown if an error was actually thrown. In other words, an error is created and its description is printed to the console, even though no error is actually thrown!
I can't figure it out. The test passes, no error is thrown, but my custom error message is printed to the console.
Aucun commentaire:
Enregistrer un commentaire