import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewPerson(t *testing.T) {
firstName := "Barack"
lastName := "Obama"
birthYear := 1990
p, err := NewPerson(firstName, lastName, birthYear)
assert.Equal(t, err, nil, "Should not return error.")
assert.Equal(t, p.FirstName, firstName, "First name came wrong.")
assert.Equal(t, p.LastName, lastName, "Last name came wrong.")
assert.Equal(t, p.BirthYear, birthYear, "Birth year name came wrong.")
}
func TestFullName(t *testing.T) {
tests := []struct{
firstName string
lastName string
fullName string
}{
{"Hello", "World", "Hello World",},
{"Barack", "Hussein Obama ", "Barack Hussein Obama",},
}
for _, obj := range tests {
p, _ := NewPerson(obj.firstName, obj.lastName, 1990)
assert.Equal(t, obj.fullName, p.FullName())
}
}
This works fine. But what happens when I've written many tests, and then I need to make a change in the "NewPerson" constructor because I've added a new property to the struct?
I will then have to change all parameters of the calls to the constructors.
What's a solution for this? Should I look for a way to abstract this?