230 likes | 419 Views
Testing. Especially Unit Testing. V-model. Wikipedia : http://en.wikipedia.org/wiki/V-Model_(software_development). Verification & Validation. Verification Phases Requirements analysis System Design Architecture Design Module Design Validation Phases Unit Testing
E N D
Testing Especially Unit Testing
V-model Wikipedia: http://en.wikipedia.org/wiki/V-Model_(software_development)
Verification & Validation • Verification Phases • Requirements analysis • System Design • Architecture Design • Module Design • Validation Phases • Unit Testing • Integration Testing • System Testing • User Acceptance Testing
Types (or Stages) of Testing(Validation) • Developer Testing • Normal testing by the developer / programmer – to see it do work • Independent and Stakeholder Testing • Independent Testing denotes the test design and implementation that it is most appropriate for someone independent from the team of developers to do. • Unit Tests • Systematic automatic test of a unit (testing from a black box view) – our focus • Integration Test • integration testing is performed to ensure that the components in combination do work (e.g. that classes across packages do work) • System Test • System testing is done when the software is functioning as a whole. Do the whole system works • Acceptance Test • The users do the testing and accepting as a final test action prior to deploying the software. Check that all use-cases and all non-functional requirements work
Unit testing • White box testing • where you check all programming lines have been executed with an accepted result • Black box testing • where you check all methods have been executed and all parameter boundaries have been checked – of cause again with an accepted result
Black-box (UPedu) • input argument • Normal values from each equivalence class. • Values on the boundary of each equivalence class. • Values outside the equivalence classes. • Illegal values. • output argument • Normal values from each equivalence class. • Values on the boundary for each equivalence class. • Values outside the equivalence classes. • Illegal values.
Set up test-cases • Follow / Fill out schema
Example - Person • Constrains: • ID a number between 1000-99999 • Namea text which is not null and at least 4 character long • Phonea number of 8 digits
Model Driven Development> Identify New Functionality Pass ImplementFunctionality and Refactor Fail Write Test Run Test
Running tests in Visual Studio [TestMethod] publicvoidconvertToInt() { } publicstaticintconvertToInt(stringbinaryNumber) { thrownewNotImplementedException(); }
A classthatneeds to beimplemented publicclassBinaryHelper { publicstaticboolgreaterThan(string p1, string p2) { thrownewNotImplementedException(); } publicstaticboolsmallerThan(String p1, String p2) { thrownewNotImplementedException(); }
Unit tests [TestClass] publicclassBinaryHelperTest { [TestMethod] publicvoidgreaterThanTest() { } [TestMethod] publicvoidsmallerThan() { }
Tool to generate first part of Unit Test • Unit Test Generator – to download and install • Link: • http://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8cff-165b505a38d7 • For more information: • http://vsartesttoolingguide.codeplex.com/releases/view/102290
The Assertclasscontinued http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.aspx
Moq4 A mockobjectframework for MStest
Moq4 example publicvoidCompleteCourseTest() { // setup mock activity var c = newMock<IActivity>(); c.Setup(m => m.GetName()).Returns("Programming"); c.Setup(m => m.getECTS()).Returns(15); // test with mock activity Student s = newStudent(); Assert.IsTrue(s.EnrollActivity(c.Object)); }