Я пишу модульные тесты для метода, который имеет утверждение. Руководство Swift Language рекомендует использовать утверждения для "недопустимых условий":
Утверждения заставляют ваше приложение завершаться и не заменяют проектирование вашего кода таким образом, чтобы недействительные условия были маловероятными возникать. Тем не менее, в ситуациях, когда недействительными являются условия возможно, утверждение является эффективным способом обеспечения того, чтобы такие условия выделены и замечены во время разработки, приложение опубликовано.
Я хочу проверить случай сбоя.
Однако в Swift (начиная с бета-версии 6) не существует XCTAssertThrows
. Как я могу написать unit test, который проверяет, что утверждение не выполнено?
Изменить
В соответствии с предложением @RobNapier я попытался обернуть XCTAssertThrows
в Objective-C и вызвать этот метод из Swift. Это не работает, так как макрос не улавливает фатальную ошибку, вызванную assert
, и, следовательно, сбой при тестировании.