coding practices - Part 1
Reply
![]() |
|
|
From:
Anand Kumar
|
Hi Group, This is with respect to my earlier mail that I will cover few tools which leverage your coding practices , today I am covering NUnit.
All developers know their code should be tested to improve its quality. However, most developers hate to test. They especially hate to test their own code, since doing so uses time that instead could be spent writing cool new features and requires them to face their own potentially imperfect code. One way around these psychological barriers to testing is to write tests before writing the code, and to make it clear that the code isn't done until it passes the tests. The tests, in turn, reflect the external requirements of the code's behavior�in essence the tests document the design of the code. Writing tests first as a methodology is known as test driven development(TDD) or test driven design to know more about TTD refer http://testdriven.com .NUnit helps to implement the TDD to improve your code quality.
NUnit is a unit testing framework build on .NET framework.It is a open source code which allows you to write tests in the language of your choice to test a specific function of your application. Unit tests are an excellent way to test the functionality of your code when you first write it, and also to provide a method for regression testing of your application. The NUnit application provides a framework for writing unit tests, as well as a graphical interface to run these tests and view the results.
Nunit is an attribute based approach testing programming for example [TestFixture] indicate that the class contains tests, [SetUp] and [TearDown], which are run before and after each test, and [Test] indicate the method marked for test.
NUnit also provides a simple graphical user interface that lets you select which assembly you want to test and which set of tests within that assembly you want to run. It then runs all of the tests in the assembly (or namespace or class) selected, displaying a green bar if everything passes and a red bar if any tests failed. Details of each failed test are also displayed, making it very easy to locate the cause of the failure
The following example shows how to test the Nunit test. namespace NUnitExample { [TestFixture] public class HashtableTest { public HashtableTest() {} [Test] public void HashtableAddTest() { ArrayList myArrList = new ArrayList(); ArrayList.Add("C-Sharp"); ArrayList.Add("VB.NET"); ArrayList.Add("MC++");
Assert.AreEqual(ArrayList[0], "VB.NET", "Wrong name returned!"); Assert.AreEqual(ArrayList[2], "C-Sharp", "Wrong name returned!"); }
} }
The current release of NUnit (1.3) capable to test the Windows Forms applications, now it is easy to write automated tests for your Windows Forms classes that means your NUnit tests can open a window and interact with the controls. Your tests will automatically manipulate and verify the properties of the GUI. NUnitForms takes care of cleaning up your forms between tests, detecting and handling modal dialog boxes, and verifying that your expectations for the test are fulfilled. Still there lots to talk about NUnit but let me stop here because I want you folks to explore . Download the open source code and document from http://nunit.org .
Cheers Anand http://spaces.msn.com/members/anandkumar
|
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|