InterestedDev
InterestedDev

Reputation: 588

Do I need to create a Unit Test Case class for a Struct in Swift?

I wonder if there is a need to create a Unit Test Case class or even a separate unit test method to test a Model of it is a Struct?

I trying to follow the TDD to create a Signup feature for my mobile app. On a piece of paper, I have sketched what I need to create:

I wonder if there is a need to create a Unit Test Case class or even a separate unit test method to test a Model of it is a Struct? Structs do not have failable initializers. And because Swift struct has a memberwise initializer, there is really nothing to test...

For example. The SignupModel.swift - a separate file:

struct SignupModel {
    let firstName: String
    let lastName: String
    let email: String
    let password: String
}

Do I really need to create a test method:

    func testInit_SignupModelExists() {
       let signupModel = SignupModel(firstName:"John", lastName: "Doe", email: "[email protected]", password: "12345678")


       XCTAssertNotNil(signupModel)
    }

Do you guys create this kind of Unit tests when following the TDD?

Upvotes: 2

Views: 1609

Answers (1)

Ekrem Duvarbasi
Ekrem Duvarbasi

Reputation: 187

You need to test your functionality with unit tests. In here, there is no any functionality.

If your init function may return nil, you may need. But in this case, your initializer never return any value but your create. So we can't say this a functionality.

Upvotes: 1

Related Questions