Message-ID: <1494003318.85762.1397699533991.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_85761_706894415.1397699533991" ------=_Part_85761_706894415.1397699533991 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Unit tests are a way of ensuring the "correctness" of = a program's behavior along side making sure that particular chunks of the p= rogram do not "regress" and cease functioning as expected. In a c= omplex application where many functions depend on the bug-free performance = of another, it is vital to make sure things behave as expected--and if they= don't, you should be alerted immediately!=20
A good unit testing framework for the .NET platform (on which Boo runs!)= is NUnit.=20
Here's a basic unit test in Boo using NUnit.=20 =20
The TestFixture attribute marks a class as containing tests to be run by= NUnit.=20
The Test attribute marks methods as being methods to be run when the tes= t fixture (SampleFixture) is being tested. This is an important attribute, = because there are helper methods we might not want to be considered as test= s.=20
"assert" is a macro in Boo that evaluates one true/false expre= ssion. If true, nothing happens. If false, however, an exception will be th= rown, and NUnit considers any unhandled exceptions being thrown a test fail= ure; therefore, we do not need to use NUnit's "Assert" class to t= est expression. The assert macro also accepts a second parameter, a message= to be printed to the console (STDOUT) if the assertion fails.=20
Crack open NUnit-Gui, open the assembly we've just created, and click &q= uot;run." The SampleFixture test fixture will fail. Why? Because altho= ugh PassTest was fine, FailTest failed its assertion (0 is NOT equal to 1),= and this causes the entire test fixture to fail. This too is important bec= ause as part of a text fixture, if any given method fails its test, than an= ything relying on that method will ultimately fail in the future. Having on= e or two passing tests is not good enough.