Suggestion on models tests.

I’ve been thinking about changing my simple model creation test from this.

def test_create_user(self):
    user = User.objects.create_user(
        email='normal@user.com',
        password='foo',
        # other fields
    )
    assert user.email == 'normal@user.com'
    # assert other fields

To this

def test_create_user(self):
    user = UserFactory.create()
    assert isinstance(user, User)

I’m not sure if they represent the same thing, but I think the second one is easier to read.

I would like to know suggesting about this kind of test, since I’m pretty new to testing thing.

Thanks for your attention.

Hi!

I like the second option. As you say, is easier to read and also it’s a common pattern.
I used factory_boy — Factory Boy latest documentation sometime ago but you can define your own factory without a 3rd party library.

Here are some other resources to take ideas on what to test: