Elegant tests with Truth Tables
brewhouse.io
Elegant tests with Truth Tables
1–10 of 12 posts
Re: Elegant tests with Truth Tables
#2https://github.com/r0man/cljs-http/blob/master/test/cljs_htt...
Re: Elegant tests with Truth Tables
#3As they are not truth tables: http://en.wikipedia.org/wiki/Truth_table
Re: Elegant tests with Truth Tables
#4I think a better name for these testing constructs would be Expectation Tables.
Re: Elegant tests with Truth Tables
#5For 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.
Re: Elegant tests with Truth Tables
#6The name "Truth Tables" in already firmly established in logic to refer to enumerations of all combinations of boolean inputs and outputs. I think a better name for these testing constructs would be Expectation Tables.
Re: Elegant tests with Truth Tables
#7Re: Elegant tests with Truth Tables
#8The name "Truth Tables" in already firmly established in logic to refer to enumerations of all combinations of boolean inputs and outputs. I think a better name for these testing constructs would be Expectation Tables.
Naming is hard! Thanks for suggesting "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.
Re: Elegant tests with Truth Tables
#9The '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...
Re: Elegant tests with Truth Tables
#10I remember Gherkin (Cucumber for Ruby) had this! It does beat having a ton of assertions.