Сбой модульного теста после перехода на Xcode 10

У меня есть набор модульных тестов для моего приложения, которые отлично работали на Xcode 9.4.1. После обновления до 10.1 у меня возникла ошибка, связанная с утверждением, что переменная слабой ссылки равна нулю после установки соответствующей переменной, на которую она указывает, равной нулю. Любые идеи, почему это не удастся теперь, когда я обновился? Другие тесты следуют этому шаблону, но не дают сбоев. РЕДАКТИРОВАТЬ: вот новый, исправный код. просто нужно было инициировать кнопку в автовыпускном пуле PerformSetup() {}...

var button: CustomButton!
var buttonSize: CGSize = CGSize(width: 0, height: 0)

override func performSetup(file: StaticString = #file, line: UInt = #line) {
    super.performSetup(file: file, line: line)


    autoreleasepool {
        if button == nil {
            button = CustomButton()
            buttonSize = button.designDataMinimumButtonSize()
        }
        addToAndCenterWithinHostView(subview: button)
    }
}

override func performTeardown(file: StaticString = #file, line: UInt = #line) {
    // Verify that no strong reference cycles keep the test objects alive.
    weak var weakComponent = button

    autoreleasepool {
        button.removeFromSuperview()
        button = nil

        super.performTeardown(file: file, line: line)
    }

    // This assertion tests for strong reference cycles in the tested code.
    // However, if the assertion fails, it may be because the test did not
    // wait for a closure that was asynchronously dispatched to finish. In
    // that case, there is not a bug in the tested code and the test should
    // be modified to wait for the dispatched closure to finish.
    XCTAssertNil(weakComponent, "Expected no strong references to 'button' to exist.")
}

person Noah    schedule 21.11.2018    source источник


Ответы (1)


Решил это, поместив инициализацию кнопки в autoreleasepool{} метода PerformSetup(). Ответ отредактирован с новым кодом...

person Noah    schedule 28.12.2018
comment
Нет, вы отредактировали вопрос. Покажите старый нерабочий код в вопросе и исправленный код в ответе. Спасибо! - person matt; 29.12.2018