Brian McCallister is up to his usual tricks. This time he didn't like JsUnit for a certain use case, so he created the embryo for a new test framework in JavaScript: For now let's call it XN.
With it you can end up with a test API such as:
JAVASCRIPT:
-
-
s.test("Asynch test which succeeds", function(t) {
-
t.async();
-
-
dojo.io.bind({
-
url: "/Give-Me-A-404", // 404
-
error: function(type, thing) {
-
t.succeed();
-
}
-
});
-
-
});
-
-
s.test("Async test which should fail", function(t) {
-
t,async();
-
-
dojo.io.bind({
-
url: "/Give-Me-A-404", // 404
-
error: function(type, thing) {
-
t.fail("Failure is on purpose");
-
}
-
});
-
-
});
-
A lot of where the design veers from standard XUnit form it is to accommodate JavaScript idiosyncrasies. For instance, if we look at the test() function we see a variable being passed in! This variable is the instance of the test case, which is also, as it so happens, the value of this in the test function.
JavaScript's scoping bizarrity makes it much more practical to pass the test case in as an argument, that way you don't have to capture the correct value of this, or pass around this as a context to other calls when using anonymous functions. Handy. The same thing applies to suite.
Defining it as a Dojo module is also handy, it makes building a real suite pretty easy, you just require each of the "suites" -- which is why I think I'll rename it to group or even testCase, but I hate the camel casing, so will think a bit :-)
Reporting success and failure is easy to override, the default just creates a definition list and plugs results in, like so. Not pretty, but easy to make pretty as time goes on.
The API exploration test cases are all online, but not especially polished. We'll see where this goes. I kind of like the feel of how it is coming together. A couple things I definitely need to do though are changing failure to raise an exception rather than allow the rest of the test to continue, which will make stack trace generation for tracking down failures more useful; and add some more assertion helper functions (oh, and add the one-argument form, always including an explanation is annoying once you have stack traces to see where it came from).
It is very cool that it plugs right into Dojo and could be a nice dojo.xn library for us to use. Obviously, it is early days, but thanks for the ride Brian and keep it up!