502045
Software Engineering
Chapter 08
Lesson 11: Testing
July 30, 2020 502045 - Testing 1
Contents
Software testing levels
Manual unit testing
Unit Testing based on UT cases
Automated Unit Testing
Automated Unit Testing with NUnit
Automated Tests vs. Manual Tests
Best Practices
July 30, 2020 502045 - Testing
Too many of Software Testing Levels
Process
Process
Test driven
Traditional
Manual Automatic Developm
Test process
ent
test test
July 30, 2020 502045 - Testing
How we test this function?
Requirement :
◦ Write a module to add an User to
Database
Business rule :
◦ Email can not be duplicated
◦ Email must be in valid form
◦ UserName ‘s length must be > 8
◦ UserName can not be dupplicated
◦ Password length must be > 8
4
July 30, 2020 502045 - Testing
Manual Unit Testing
Write code
Uploading the code to some place
Build it
Running the code manually (in many
cases filling up forms etc step by step)
Check Log files, Database, External
Services, Values of variable names,
Output on the screen etc
If it does not work, repeat the above
process 5
July 30, 2020 502045 - Testing
Manual Unit Testing - Limitation
Itdepends on developer’s memory
The more test case, the less coverability of
developer
Many duplicate test cases
Lack of test cases
Team lead cannot review everything
July 30, 2020 502045 - Testing
Unit Testing based on UT cases
Describe test cases on word or excel
July 30, 2020 502045 - Testing
Automated Unit Testing
First Step
Coding Process with Automated Unit Tests
◦ Write code
◦ Write one or more test cases script
◦ Auto-compile and run
◦ If tests fail -> make appropriate
modifications
◦ If tests pass -> repeat for next method
July 30, 2020 502045 - Testing
Automated Unit Testing
Common Tools
UT Tools for references:
◦ Java: JUnit, J2MEUnit
◦ C/C++: cppUnit
◦ Python: pyUnit
◦ Perl: PerlUnit
◦ Visual Basic: vbUnit
◦ C# .NET: Nunit,csUnit
Refferences:
[Link]
[Link]
[Link]
July 30, 2020 502045 - Testing
Automated Unit Testing
Common Tools
[Link]
[Link]
[Link]
10
July 30, 2020 502045 - Testing
Automated Unit Testing Demo
11
July 30, 2020 502045 - Testing
Automated Unit Testing with NUnit
What is NUnit?
Milk ? Beer
or Coffee?
NUnit – an open source test tool for .NET
Useful for development and regression
Leads to a design-for-test approach
Tests can be written in [Link] or C#
12
July 30, 2020 502045 - Testing
Automated Unit Testing with NUnit
Where to get NUnit?
Let’s go to website:
[Link]
Yeahh, I
got it
13
July 30, 2020 502045 - Testing
Automated Unit Testing with NUnit
Where to get Nunit? - Extract to any folder
mumm, it
is easy
14
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Screens of tool
Yeahh, It
tastes
good
15
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
How to use NUnit?
Create a test case base on NUnit
framework
Deploy and Run
Who
knows…
16
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Create a test case
Step 1: Create a Class
Step 2: Add a reference [Link]
to this class
Step 3: Add a reference to *.dll contains
function which you want to do Unit test
Step 4: Restructure class following Nunit
frame work
Step 5: Write a test case
Let’s me
go…
17
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Create a test case
Step 1: Create a Class
Step 2: Add a reference
[Link] to this
class
Step 3: Add a reference to
*.dll contains function
which you want to do Unit
test
Step 4: Restructure class
following Nunit frame work
18
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Create a test case
Step 5: Write a test case
Each test case will be a function/method of class
Must have attribute [Test] above a
function/method
Ex:
[Test]
public void testCase1()
{
[Link](0, intA);
}
[Test]
public void testCase2()
{
[Link](0, divides(intA, Beer
intB));
Please !!!
}
19
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Core Features
Core Features to code a test case
Assertions
• Equality Assserts:
– Ex: [Link]( int expected, int
actual );
• Condition Tests:
– Ex: [Link]( bool condition );
• Comparrison Asserts
– Ex: [Link]( int arg1, int arg2 );
• Type Asserts
– Ex: [Link]( Type
expected, object actual );
• Utility methods
– Ex: [Link]();
• String Assert
– Ex: [Link]( string expected,
string actual );
• Collection Asserts
– Ex: [Link]( Collection
expected, Collection actual ); 20
Attributes
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Attributes
Core Features
[TestFixture]
[Category("TestUnitExample")]
public class TestNUnit
{
private int intA;
private int intB;
private CaculatesSomeThings objCal;
[SetUp]
protected void SetUp()
{
intA = 0;
intB = 0;
objCal = new CaculatesSomeThings();
}
[Test]
Public void TestCase1()
{
[Link](0, [Link](intA,
intB))
}
21
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Deploy and Run
Step 1: Compile a test case class to dll
Step 2: Run NUnit tool
Step 3: Open *.dll contains test case class
Step 4: Choose the test case you want to run
Step 5: Click run button to see the report
I don’t
believe…
22
July 30, 2020 502045 - Testing
Automated Unit Testing with Nunit
Deploy and Run
Quality…
God let me
sleep
23
July 30, 2020 502045 - Testing