-
Notifications
You must be signed in to change notification settings - Fork 517
add docs on detailed error messages on assertion failures #160
Comments
I think you are looking for the The helpers are separated into libraries based on their role.
To help others write similar helpers, the underlying primitives, e.g. output formatting, have been abstracted out into Check out the Readme of each library and the shared documentation For the philosophy and design of these libraries see the discussion in #110. |
@ztombol, it's quite a pity that your nice helpers were not merged into BATS and even more pity that they were not mentioned in BATS' docs. I have implemented all my tests using "plain" BATS+bash infrastructure before I got your answer. By the way, I used BATS to test REST API of a web-service. Now I am asked to output all curl-invocations that have been issued against the web-service. That is, print out all commands passed during invocations of the BATS "run" function. Probably, with your helpers such a verbosity would have been easy to add. Well, said all that, I am looking forward to use your code in my next tasks. |
@vak The Bats has been understaffed for some time (hence the lack of a new releas or merged PRs). The author started gathering manpower in #150 to get development going again, and it's been going well! I've been writing up a list of changes I will suggest to be addressed in the coming releases. Adding a reference to Don't worry if you have already completed your test suite without the use of these libraries. Migration is trivial and quick. Simple regular expression find-and-replace commands will do that for you in no time. I did it for one of my projects. Regarding your question. The assertions in #!/usr/bin/env bats
# Log into `test.log'.
log() {
echo "$@" >> 'test.log'
}
# Test a call to the REST API and log all passing calls.
assert_rest_call() {
local -r command="curl <options> $@"
run "$command"
if (( status )); then
# Add failure details to be displayed by bats here!
return 1
fi
log "$command"
}
@test 'REST API call' {
assert_rest_call '<call>'
} I suggest you write general purpose assertions and helpers and compile them into a helper library for testing REST APIs (or maybe someone has already done so?). This way you can use it in multiple projects and if you publish it others can help you improve it. For examples, see the libraries listed in |
Hi
many thanks for your time invested in BATS. BATS is really helping.
It would be nice, if BATS developers could add a few lines in docs about the way of printing detailed error messages from failing assertions.
The easiest way to get a hint on what happens in a failing assertion is to write assertions with comments like:
So, when it happens one could see not only the corresponding failing statement of the .bats test file, but also the comment line in addition. However if we'd like to see in test logs some hint on why it happened (e.g., invocation details, response details, variables, etc) then we'd need to echo details to stderr in some BATS-friendly manner.
One could add perhaps the following recipe for the BATS-beginners.
and use it like:
or maybe you have even better way to print out it :)
kind regards,
Valery
The text was updated successfully, but these errors were encountered: