Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Tests for UIlabel #51

Open
grantkemp opened this issue Aug 9, 2016 · 0 comments
Open

Creating Tests for UIlabel #51

grantkemp opened this issue Aug 9, 2016 · 0 comments

Comments

@grantkemp
Copy link

grantkemp commented Aug 9, 2016

I am trying to do a test for the updateCounter() Method however it keeps returning nil and crashing

func UpdateTimer() {
Counter = Counter + 0.1
timeLabel.text = String(format: "%.1f", Counter)
}

Here is the code I used to generate the test, and tried to use a fake UIlabel to capture the update method.

class StopWatchTests: XCTestCase {
var sut:ViewController!

override func setUp() {
    super.setUp()
    sut = ViewController()
    let testingUIlabelFrame = CGRectMake(5, 5, 100, 100)
    sut.timeLabel = UILabel(frame: testingUIlabelFrame)
    sut.timeLabel.text = "test"
}

override func tearDown() {

    super.tearDown()
    sut = nil
}

func testUpdateTimere() {
    //Test that counter is incremented by one
   sut.Counter = 10
    sut.UpdateTimer()
    XCTAssertEqual(sut.Counter, 11)

    let timelabel = sut.timeLabel.text
}

Besides refactoring the logic to move the ui update to a different method - is there any way to make above work as is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant