This is a common practice and more often than not the data is reused, so it is provided by a "data provider", a method living in the test code, which returns a structure with inputs and expected results.
It would actually be even more elegant if the data where extracted out of the test methods in my opinion. Though it would effectively double the number of methods, it cleans things up significantly within the test methods, provides an outlet for extension and the only expense is the addition of declaration & closing lines.
The 'table' consists of an array of calls to constructors of structs that contain fields which are used to set up the context for each test, set value expectations specific to that test, and whether certain tests in shared examples apply to that context.
There is a certain level of cognitive overhead involved in understanding this method of writing tests, to be sure, but the benefits (concise expression of a huge matrix of variations) outweigh the costs (massive duplication, and therefore comprehension of thousands of more lines of test code).
It's important to note that this style of test is really best for the situation where there is a large matrix of things you'd like to test.
11 comments
[ 2.5 ms ] story [ 33.3 ms ] threadhttps://github.com/r0man/cljs-http/blob/master/test/cljs_htt...
As they are not truth tables: http://en.wikipedia.org/wiki/Truth_table
I think a better name for these testing constructs would be Expectation Tables.
But coming from an EE/CE digital logic background, if it doesn't have 1's and 0's (or T's and F's) in it, it just ain't a Truth Table to me.
Of course I could just as easily be criticized for "Expectation Tables" by someone in obstetrics, so what's fair is fair.
I do like your design. Nice job.
For example, in PHPUnit: https://phpunit.de/manual/current/en/writing-tests-for-phpun...
It would actually be even more elegant if the data where extracted out of the test methods in my opinion. Though it would effectively double the number of methods, it cleans things up significantly within the test methods, provides an outlet for extension and the only expense is the addition of declaration & closing lines.
The 'table' consists of an array of calls to constructors of structs that contain fields which are used to set up the context for each test, set value expectations specific to that test, and whether certain tests in shared examples apply to that context.
There is a certain level of cognitive overhead involved in understanding this method of writing tests, to be sure, but the benefits (concise expression of a huge matrix of variations) outweigh the costs (massive duplication, and therefore comprehension of thousands of more lines of test code).
It's important to note that this style of test is really best for the situation where there is a large matrix of things you'd like to test.
The example I linked included ~70 different contexts, each of which is being run through the large Test() function at the bottom: https://github.com/cloudfoundry-incubator/runtime-schema/blo...
Just more of the same idea and I think the resulting tests are easier to understand. Good writeup.
Please take a look at my article: http://technology.indiegogo.com/2015/01/ascii-tables-for-cle...
And the gem: https://github.com/IndieGoGo/atv
+------+-------+ | name | Kelly | +------+-------+