1. Unit Tests & Automated Testing Lee Englestone presents.. www.manchesterdeveloper.com
2. Agenda Terminology What, Why, How Automating unit tests & testing Advanced stuff Test driven development (TDD) Code coverage What we wont be covering Continuous Integration (in any depth)
3. Terminology (for the next hour) Unit test Tests a small bit of code (from code) Integration test Test after addition of code System test / functional test Test for adherence to user requirements Regression test Test that fixing / adding code hasn’t introduced bugs Continuous integration Automated checkout, building and testing of code from source control Source : Lee & Wikipedia
4. Why should we TEST? Why should we test at all? £ £ REMEMBER Testing is just one step in QA £ £ £ £ £
6. Three tier architecture Web UI ASPX, ASCX, HTML, Flash, EpiServer Page Templates etc Business Logic Code libraries (DLLs) Business Logic (DLL) Database access Data Access Layer
7. Testing business logic Code libraries (DLLs) Business Logic (DLL) Unit Tests (DLL) Unit Tests (DLLs) Database access Data Access Layer
8. Why have unit tests? Why have unit tests? Find bugs early / fast feedback Increase QA Why not to have unit tests Increases development time? CostOfWritingUnitTests < Sum(BugFixing)
10. What is a unit test? “..tests if individual units of source code are fit for use.” Should be Small Specific (only test 1 thing) Clear pass / fail criteria
11. What does a unit test look like? Using NUnit.Framework; [TestFixture] public class CarTests { [Test] public void Test_Car_Paint () { // Arrange Color paint = Color.Red; Car car = new Car(); // Act car.paint(Color.Red); // Assert Assert.AreEqual(car.Color, paint); } … } Arrange Act Assert
13. An example scenario { Code Example } Objects Car Properties ColorColor double Value double FuelLevel double FuelCapacity FuelTypeEnumFuelType Methods Car.Crush() Car.Paint(Color) Car.AddFuel(FuelTypeEnum, double) Car.VeryImportantMethod()
15. Testing Web UI (Selenium) What if we want to test the UI? Manual recording and running Can export to NUnit Examples : Community Fund Form H1 checking** { Code Example }
16. Test driven development (TDD) Write your tests, even BEFORE your code! Make sure all tests initially fail Then implement the code that the tests are testing (Encourages Designing for Testing)
21. Testing Terminology (Wikipedia) Unit test “..a programmer tests if individual units of source code are fit for use.” Integration test “..individual software modules are combined and tested as a group. It occurs after unit testing and before system testing.” System test / functional test “..testing conducted on a complete, integrated system to evaluate the system's compliance with its specified requirements. Regression test “..seeks to uncover software errors by partially retesting a modified program. The intent of regression testing is to assure that a bug fix has been successfully corrected .. , while providing a general assurance that no other errors were introduced in the process of fixing the original problem.” Continuous integration Automated checkout, building and testing of code from source control Source : Wikipedia
Notes de l'éditeur
There are no silver bullets in development.Developers have are there disposal an arsenal tools, and they must be used in the right way to fit company processes