bash_test_tools
bash_test_tools copied to clipboard
Run setup/teardown once but not for every test
Hi! Started to use bash test tools and really like it!
But I'm looking for possibility to run setup/teardown function only once. As example, in setup I prepare some data to check, and in the same script I have 4 tests which test prepared data. Currently if I'm running test script, setup and teardown functions are called for each test, so setup and teardown are running 4 times. Is there any way to run them only once - before and after ALL tests in script executed?
Thanks. Typically the setup and teardown are run before every test to help ensure a standard environment for each test. I.e. to avoid one test_ function affecting the results of another test_ function.
We could add some kind of global setup and global teardown as you suggest. But before we do that, do you think it would be OK in your use case to have within one test function, a number of run calls followed by asserts... I.e. would something like this work for you?
function test_a_few_procedures
{
# Run first program
run "myprog1 --some-args"
# Assert first program
assert_success
...
\# Run second program
run "myprog2 --some-args"
# Assert second program
assert_success
...
etc.
}
If this is suitable for your case, then maybe there is no need for the global setup/teardown you suggest. But let me know what you think.
These are not very popular tools yet :) But I find them useful and dead simple for myself. If you like the concept of it you are most welcome to contribute. No problem adding you as contributor.
Thank you for fast response and quick solution. Not sure if it suitable for my case, but will try. In other hand global setup/teardown would allow to run by suites of tests, having them separately and without duplicating code and/or external scripts.
Yeah, I know, people most use high lvl programming languages.But in my case I should validate a lot of data, accessing to files from terminal. Plus there are a lot of scripts. So automation of this testing with bash seems to me logical. I just started to use it, but I really like it. Thanks for external asserts - cool feature, I believe I will use it from time to time. Regarding contributing - I really appreciate this, but I don't have such expertise I think :) I'm nit very experienced in shell scripting.
Yes, testing command line programs in the shell is useful in many cases. I think these are kind of black box / system tests. Not as powerful as testing the insides of programs using unit and integration tests, but I ended up with this because I did not like testing things by hand and at my company we had inherited some code that could for the time being only be tested as a black box.
I'll look into adding some global setup / teardown in the next few days, and let you know. I think it could in fact be useful to improve some tests I am already having problems with -- for example a global setup / teardown could be used to download some large test data... I really don't want to do that on every test run :)