Browse files

Added config option to ignore tests with no asserts

  • Loading branch information...
1 parent 940897c commit 24fecdd30572d44f01eb977f111079740c595c8d @davglass committed Feb 22, 2012
Showing with 11 additions and 2 deletions.
  1. +11 −2 javascript/src/core/TestRunner.js
@@ -210,10 +210,19 @@
* @static
this._groups = "";
TestRunner.prototype = YUITest.Util.mix(new YUITest.EventTarget(), {
+ /**
+ * If true, YUITest will not fire an error for tests with no Asserts.
+ * @prop ignoreEmpty
+ * @type Boolean
+ * @static
+ */
+ ignoreEmpty: false,
//restore prototype
constructor: YUITest.TestRunner,
@@ -596,7 +605,7 @@, this._context);
//if the test hasn't already failed and doesn't have any asserts...
- if(YUITest.Assert._getCount() == 0){
+ if(YUITest.Assert._getCount() == 0 && !this.ignoreEmpty){
throw new YUITest.AssertionError("Test has no asserts.");
//if it should fail, and it got here, then it's a fail because it didn't

4 comments on commit 24fecdd

The run() method accepts an options object that defines how the tests should be run. I think this would be better as an option on that object.


davglass replied Feb 22, 2012

I didn't add it there because I wanted all tests to abide by this out of the box. With our large system, I didn't want to have to modify every single test module to add this parameter for backward compatibility. This gives a "one stop" place to set this and have it "just work" as it did before that assert was added.

I understand the intent, the problem is that this would create two places to specify options instead of one. I don't like the idea of having a global configuration for the TestRunner because your tests may have different results depending on the TestRunner being used...that should never happen. Also, having tests without asserts is a horrible practice, and I don't want to encourage that.

That being said, I'm willing to compromise with you. If you want this property, mark it as private and deprecated, and prefix it with an underscore. That way, at least it will be hidden or flagged in docs as something people shouldn't use. It can be a YUI-only thing.


davglass replied Feb 22, 2012

That works! On it..

Please sign in to comment.