Failures, Errors, and Script Errors

This example is based on Examples/Tests/Error Conditions/ErrorTests.js, Examples/Tests/Error Conditions/FailureTests.js, and Examples/Tests/Error Conditions/ScriptErrorTests.js from examples.zip.

xUnit.js provides several levels of interruption:

Failures:

Failures are violations of test expectations. These are considered normal, and do not interrupt test runs. They are caused by a failed assertion, or a thrown xUnit.js.Model.AssertError: Function.RegisterNamespace("Test.ErrorConditions"); [Fixture] Test.ErrorConditions.FailureTests=function(){ [Fact] function FailsOnEqualityAssertion(){ var expected=true; var actual=false; Assert.Equal(expected, actual); } }

Errors:

Errors are syntax or language violations that occur inside a test. These are also considered normal and do not interrupt test runs: Function.RegisterNamespace("Test.ErrorConditions"); [Fixture] Test.ErrorConditions.ErrorTests=function(){ [Fact] function ErrorsOnUnknownMember(){ var expected=true; var actual={value:true}.slice(0,1); Assert.Equal(expected, actual); } }

Script Errors:

Script Errors represent syntax or language violations that occur outside of a test. These can prevent test registration, and halt the interpretation of files and fixtures. Script Errors should be addressed before Failures or regular Errors, as they have the ability to conceal multiple issues: Function.RegisterNamespace("Test.ErrorConditions"); [Fixture] Test.ErrorConditions.ScriptErrorTests=function(){ [Fact] function ThrowsSyntaxErrorOnLoad(){ var expected=if(true)); var actual=false; Assert.Equal(expected, actual); } }

System Errors:

System Errors are script errors that occur during the execution of the script load or action steps of an xUnit.js console run. These are typically only produced by errors in custom host enviornment or I/O strategies. System Errors are halting, and abort the run, but still attempt to complete the epilogue of the output strategy.

Critical Errors:

Critical Errors are game over, man. If a script error occurs while collecting runtime parameters in the environment strategy; during the load of a script dependency; or in the output prologue; the entire run is aborted, and no attempt at recovery is made.