Search code examples
gotestify

How to receive multiple values returned by a method in testify framework "assert" method as an argument?


Below is a sample code , which is returning multiple values .

func (c Calc) CreateTenantHandler(item *models.TenantInput) (*models.Response, *models.ErrorDetails) {

        ...
        ...
        ...

        return &models.Response{ResponseStatus: 201, TenantOutput: tenantoutput,}, nil

    }

In test file I have tried tried doing below things.

assert.Equal(t,[nil,nil],testObject.CreateTenantHandler(nil) );

I also checked other answers but couldn't find what I need.


Solution

  • You don't. It has nothing to do with testify--that's just how Go works. Set multiple variables to the return values, then assert each one individually:

    x, y := testObject.CreateTenantHandler(nil)
    assertEqual(t, x, expectedX)
    assertEqual(t, y, expectedY)