Giter Site home page Giter Site logo

Proposal: Must-like utility about testify HOT 3 CLOSED

seiyab avatar seiyab commented on June 15, 2024
Proposal: Must-like utility

from testify.

Comments (3)

brackendawson avatar brackendawson commented on June 15, 2024 2

Parking for now. If anyone feels strongly in favour of the feature then feel free to post your reasoning.

from testify.

brackendawson avatar brackendawson commented on June 15, 2024 1

So this is like the well known generic Must(), but rather than converting non-nil errors to a panic, it converts non-nil errors to a fatal test failure.

Would assert.Must exist? Would it be a non-fatal test failure? If it did then it would feel very wrong calling it "must". Probably it would only apply to require.

You only show usage in test setup, which is not the primary purpose of test assertions. How does this look in a test assertion?

actual := require.Must(t, codeundertest.GetData(arg))
require.Equal(t, expected, actual)

Sure, maybe, but do we also need Must2, Must3 etc.. Because type parameters cannot be variadic. It looks like Go is not going to add Must to the standard library: golang/go#32219

In my view this turns 3 lines into 2 for test assertions, 2 lines into 1 for test setup. At best it doesn't make the test more readable. I don't think we should include this.

from testify.

seiyab avatar seiyab commented on June 15, 2024

Rethinking it, I agree that it doesn't look to suit this project enough.

You only show usage in test setup, which is not the primary purpose of test assertions. How does this look in a test assertion?

Your example looks appropriate. More clear one:

// setup
x := Setup()

// act
x.MethodUnderTest()

// assertion
actual := require.Must(t, x.Get())
require.Equal(t, expected, actual)

Anyway probably it will mostly used for setup.

In my view this turns 3 lines into 2 for test assertions, 2 lines into 1 for test setup. At best it doesn't make the test more readable. I don't think we should include this.

Now I agree with you. I'd thought that it it turns 10 lines into 5 lines for test setup and it makes sense. However, probably we should just write a setup function if setup needs 10 lines.

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.