Skip to content

What is the reason to UNIT TEST like use test framework such Jest or Vitest, what is the benefit ? #128236

Closed Answered by anko
gaomingzhao666 asked this question in Programming Help
Discussion options

You must be logged in to vote

I agree that a framework is often overkill. What matters is that the tests are useful. If you can do that without a library, great.

One benefit of testing frameworks however is that they give helpful errors when tests fail. A test framework for the test you listed would typically generates output like:

In test 'adds 1 + 2 to equal 3': Unexpected value `4`. (Expected `3`.)

Some even use a highlighted diff, to help spot differences in large compared objects.

In contrast:

  • If you just use logging, you would have to check the results manually.

  • If you use a function call like console.assert that simply errors if the check fails, you will get a less specific error:

    console.assert(1 + 2 == 4)
    

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@gaomingzhao666
Comment options

Comment options

You must be logged in to vote
2 replies
@gaomingzhao666
Comment options

@gaomingzhao666
Comment options

Answer selected by gaomingzhao666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment