-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: implement unit testing framework #111
Conversation
|
name: string,required | ||
cases: object[],optional | ||
// if cases is not null | ||
evalute(case):: (object -> CaseResult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: evaluate
same 2 lines down
Tests can also be written as functions. e.g. these are valid: local expect = (import "stdlib/truth.jsonnet").expect;
local expectations = (import "stdlib/truth.jsonnet").expectations;
{
"Test test function passing": function()
local a = 1 + 2;
expectations([
expect()
.that(a)
.hasType("number"),
expect()
.that(a)
.isEqualTo(3),
]),
"Test test function failing"():
local a = 1 + 2;
expect()
.that(a)
.isEqualTo(4),
} One huge drawback with this approach is that it's still impossible to test routines that throw exceptions |
This is definitely interesting. In the case of the arith_bools it has more than tripled in size. Ideally there would have been a reduction in size. For the sake of argument, maybe it could look like this:
I also think we should try to use this framework for something more "real". How about your Kubernetes stuff? If not, there is a whole bunch of abstract templates in micromanage we can use. I think there's a big win for unit testing library abstractions (whether mixins or functions) that check that they can be instantiated into either something specific, or at least into something that has a set of expected properties. It would help document their interfaces as well as allowing refactoring with confidence. |
I'll close this for now since this can be easily implemented in a library. |
Supports tests of type function, and "table tests". Output looks like: