Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)
-
Upload
mabel-ford -
Category
Documents
-
view
223 -
download
2
Transcript of Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)
![Page 1: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/1.jpg)
TestingEspecially Unit Testing
![Page 2: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/2.jpg)
V-model
Wikipedia: http://en.wikipedia.org/wiki/V-Model_(software_development)
![Page 3: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/3.jpg)
Verification & Validation
• Verification Phases• Requirements analysis• System Design• Architecture Design• Module Design
• Validation Phases• Unit Testing• Integration Testing• System Testing• User Acceptance Testing
![Page 4: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/4.jpg)
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
![Page 5: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/5.jpg)
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
![Page 6: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/6.jpg)
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.
![Page 7: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/7.jpg)
Set up test-cases
• Follow / Fill out schema
Test case # Description of test case
Expected value
Passed succesfully
1 . . . . . .
![Page 8: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/8.jpg)
Example - Person
Constrains:•ID a number between 1000-99999•Name a text which is not null and at least 4 character long•Phone a number of 8 digits
Person
Attributes
- ID : int- Name : string- Phone : int
Operations
![Page 9: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/9.jpg)
Test case #
Description of test case Expected value Passed successfully
1 Default constructor Object created 2 Set ID – value 999 ArgumentException 3 Set ID – value 1000 ID == 1000 4 Set ID – value 99999 ID == 99999 5 Set ID – value 100000 ArgumentException 6 Set ID – value 5678 ID == 5678 7 Set ID – value -5 ArgumentException 8 Set Name – value null ArgumentException 9 Set Name – value empty (“”) ArgumentException 10 Set Name – value not empty but less than 4
value “123”ArgumentException
11 Set Name – value not empty and 4 value “1234”
Name == “1234”
12 Set Name – value not empty and 15 value “123456789012345”
Name == “123456789012345”
![Page 10: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/10.jpg)
13 Set Phone – value 9999999 ArgumentException
14 Set Phone – value 10000000 Phone == 10000000
15 Set Phone – value 99999999 Phone == 99999999
16 Set Phone – value 100000000 ArgumentException
17 Set Phone – value 56781234 Phone == 56781234
18 Set Phone – value -5 ArgumentException
19 Constructor(2222,”Susanne”,12345678) ID == 2222Name == “Susanne”Phone == 12345678
20 Constructor(00999,”Susanne”,12345678) ArgumentException
21 Constructor(2222,null,12345678) ArgumentException
22 Constructor(2222,”Per”,12345678) ArgumentException
23 Constructor(2222,”Susanne”,1234567890) ArgumentException
![Page 11: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/11.jpg)
Model Driven Development>
Identify New Functionality
Write Test Run TestImplement
Functionality and Refactor
Pass
Fail
![Page 12: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/12.jpg)
Running tests in Visual Studio
[Test
Method
]
publ
ic voi
d conv
ertToI
nt()
{
} public static int convertToInt(string
binaryNumber)
{
throw new
NotImplementedException();
}
![Page 13: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/13.jpg)
A class that needs to be implementedpublic class BinaryHelper { public static bool greaterThan(string p1, string p2) { throw new NotImplementedException(); }
public static bool smallerThan(String p1, String p2) { throw new NotImplementedException(); }
![Page 14: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/14.jpg)
Unit tests [TestClass]
public class BinaryHelperTest
{
[TestMethod]
public void greaterThanTest()
{
}
[TestMethod]
public void smallerThan()
{
}
![Page 15: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/15.jpg)
Tool to generate first part of Unit Test• Unit Test Generator
– to download and install• Link:• http://visualstudiogallery.msdn.microsoft.com/45208924-e7b0-45df-8
cff-165b505a38d7
• For more information:• http://vsartesttoolingguide.codeplex.com/releases/view/102290
![Page 16: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/16.jpg)
![Page 17: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/17.jpg)
The Assert class
Method Name DEscription
AreEqual(Object, Object) Verifies that two specified objects are equal. The assertion fails if the objects are not equal. (Overwritten with allprimitive datatypes)
AreNotEqual(Object, Object) Verifies that two specified objects are not equal. The assertion fails if the objects are equal.(Overwritten with allprimitive datatypes)
AreSame(Object, Object) Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects.
AreNotSame(Object, Object) Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object.
![Page 18: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/18.jpg)
The Assert class continued
Method Name DEscription
IsFalse(Boolean) Verifies that the specified condition is false. The assertion fails if the condition is true.
IsTrue(Boolean) Verifies that the specified condition is true. The assertion fails if the condition is false.
IsNull(Object) Verifies that the specified object is null. The assertion fails if it is notnull.
IsNotNull(Object) Verifies that the specified object is not null. The assertion fails if it isnull.
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.aspx
![Page 19: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/19.jpg)
Mock objects
![Page 20: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/20.jpg)
Test Student Class
Student
FirstNAmeLastNamecoursesJoinCourseListCourses
Course
NameECTSpoints
![Page 21: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/21.jpg)
Using Mock objects
Student
FirstNAmeLastNamecoursesJoinCourseListCourses
Mock Object
![Page 22: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/22.jpg)
Moq4A mock object framework for MStest
![Page 23: Testing Especially Unit Testing. V-model Wikipedia: software_development)software_development)](https://reader030.fdocuments.us/reader030/viewer/2022032611/56649e885503460f94b8d48c/html5/thumbnails/23.jpg)
Moq4 example
public void CompleteCourseTest() { // setup mock activity var c = new Mock<IActivity>(); c.Setup(m => m.GetName()).Returns("Programming"); c.Setup(m => m.getECTS()).Returns(15);
// test with mock activity Student s = new Student(); Assert.IsTrue(s.EnrollActivity(c.Object)); }