Unit Testing / Mocking Techniques

Introduction to Unit Testing Unit Testing The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect under various conditions. Benefits Unit testing has proven its value in that a large percentage of defects are identified during its use. If you detect and solve bugs closer to the time they are introduced, it’s a lot faster than having to locate, debug, and resolve a bug in the future. You know that your code works as you expect it to work. With unit tests in place, you know that your foundation code is dependable. It’s a good way to test first hand how your API is going to be used. Unit Testing verses Integration Testing The difference between unit testing and integration testing is important to recognize. What is a unit test? A unit test is code that tests one single method or function and checks … [Read more...]

NHibernate/DAO Unit testing

Unit Testing with using NHibernate and Data Access Objects [TestClass] public class AccountTest { private DATestHelper<CustomerDAO, CustomerDE> dh = new DATestHelper<CustomerDAO, CustomerDE>(); private DATestHelper<ProductDAO, ProductDE> dhProduct = new DATestHelper<ProductDAO, ProductDE>(); [TestInitialize()] public void TestInitialize() { dh.Init(); dhProduct.InitJoinSession(dh.session); } [TestCleanup()] public void TestCleanup() { dh.Cleanup(); dhProduct.CleanupJoinedSession(); } [TestMethod] public void GetAccountById() { CustomerDE c = dh.dao.FindById(1231); Assert.IsNotNull(c); } [TestMethod] public void GetProductByCode() { … [Read more...]