Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Failing tests don't output the actual value #190

Closed
mttkay opened this issue Oct 28, 2016 · 2 comments
Closed

Failing tests don't output the actual value #190

mttkay opened this issue Oct 28, 2016 · 2 comments

Comments

@mttkay
Copy link

mttkay commented Oct 28, 2016

If you have a failing test, there isn't really anything actionable in the test output to go on, since the only thing bats recognizes is that one of the assertions failed. So it will print something like:

`[ "$status" -eq 0 ]' failed

But what was the actual status?

Since the run function already captures the output of the given command, is it possible to pass this along and report it together with an "assertion"?

Maybe this is more something for an "assertion functions" layer on top of bats? In any way, I would expect from a test suite to be able to tell me what output the unit under test produced.

@ztombol
Copy link

ztombol commented Oct 28, 2016

Bats is intentionally kept simple. Only the developer knows what information is useful in debugging a given test case. Showing everything automatically would be just as bad.

So if you want feedback on a failing test, you have to make that happen yourself. Which is pretty easy, given the variables Bats exposes. For example:

@test 'test-a' {
  run false
  if [ "$status" -ne 0 ]; then
    echo "ERROR: status = $status"
    return 1
  fi
}

This actually came up many times before. With help from others, I wrote libraries that implement common assertions and provide useful feedback when they fail. See #110 for its design.

See also bats-docs for more information.

@mttkay
Copy link
Author

mttkay commented Oct 28, 2016

Ah great--this is exactly what I was looking for. 👍 So these projects are unrelated to the core project? Again, linking to them from the main README would be ace, since adding proper assertions is probably the first thing users would want to do.

Only the developer knows what information is useful in debugging a given test case. Showing everything automatically would be just as bad.

Every unit test framework I've ever used had some standard way of informing you what the failing result actually was. But I completely agree this can or should be factored out into an assertions module, it's just that it's kinda hard to discover this when turning to bats for the first time as there's no mention of it anywhere here.

Anyway, thanks for pointing it out!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants