Presiding Officer Training module 2024 lok sabha elections
Software testing lab 7 & 8
1. Software Testing Lab
(Lab 7 & 8)
By: Ms. Aroosa Hameed
DEPARTMENT OF SOFTWARE ENGINEERING (DSE)
Foundation University Rawalpindi Campus (FURC)
2. Lab Agenda
• Unit Testing
• What is NUnit
• NUnit
Introduction
Setup
Configuration
• Example (Test case)
• Exercise
SEN 461L - Software Testing Lab by Aroosa Hameed 2
3. What is unit testing
• Unit testing is a software testing method by which individual units of source code
are tested to determine whether they are fit for use.
• Units are:
Functions.
Methods.
Class.
SEN 461L - Software Testing Lab by Aroosa Hameed 3
4. Unit Testing (Cont.)
• Intuitively, one can view a unit as the smallest testable part of an application.
• Unit tests are short code fragments created by programmers during the
development process.
• It forms the basis for component testing.
• When we test individual function behavior without touching any other functions
and determine whether it works exactly as per the requirements or not that is
called Unit Testing.
SEN 461L - Software Testing Lab by Aroosa Hameed 4
5. Unit Testing (Cont.)
• Some of the advantages of Unit Testing:
Defects found early in development life cycle
Reliable Code
Maintainable code
Faster testing by only single click of action
SEN 461L - Software Testing Lab by Aroosa Hameed 5
6. NUnit
• NUnit is a unit testing framework.
• It is the most used framework for writing unit test cases.
• Test Assemblies:
It is suggested to write testing code in different assemblies called Test
Assemblies. These assemblies only contain testing code nothing else.
We need to run these test assemblies to check whether all test cases are
passed or failed.
For that we required Test Runner.
SEN 461L - Software Testing Lab by Aroosa Hameed 6
7. NUnit
• Test Runners are UI tool which actually run NUnit test cases and show the result
of test cases whether they are passed or failed.
• NUnit is very easy to use. It only provides some custom attributes and some static
Assert classes.
• With the combination of custom attributes and static classes, we can write unit
test cases easily.
SEN 461L - Software Testing Lab by Aroosa Hameed 7
8. NUnit
• Custom attributes provides hint to NUnit test runners that these classes or
functions contains unit testing code.
• Assert classes is used to test the conditions whether system under test (SUT)
satisfy a condition or not.
• If condition is satisfied then test is pass else fail.
SEN 461L - Software Testing Lab by Aroosa Hameed 8
9. NUnit
• Some of the custom attributes are:
TestFixture
Setup
TearDown
Test
Category
Ignore
TestCase
Repeat
MaxTime
SEN 461L - Software Testing Lab by Aroosa Hameed 9
10. NUnit Setup
• There are two steps in configure NUnit project environment:
1. Configure Project with NUnit assemblies
2. Setup TestRunners which show the results of NUnit test cases
SEN 461L - Software Testing Lab by Aroosa Hameed 10
11. NUnit Setup
• We always creates separate project when creating project for NUnit.
• According to naming conventions test project name should be [Project Under
Test].[Tests].
• For example, if we are testing the project name "CustomerOrderService" then
test project name should be "CustomerOrderService.Tests"
SEN 461L - Software Testing Lab by Aroosa Hameed 11
12. NUnit Setup (Configuring Nunit Assemblies)
1. Visual Studio -> New Project -> Class Library -> Name: CustomerOrderService
2. Right click on solution -> Add New Project -> Class Library -> Name:
CustomerOrderService.Tests
• In CustomerOrderService project, we write code for business logic
• In second project CustomerOrderService.Tests we write test cases for
CustomerOrderService project.
SEN 461L - Software Testing Lab by Aroosa Hameed 12
13. NUnit Setup (Configuring Nunit Assemblies)
• Right click on CustomerOrderService.Tests and choose "Manage NuGet
Packages".
• In NuGet search box, Choose Browse tab and type Nunit in search textbox.
• Choose NUnit and click on Install button.
• NUnit assembly (nunit.framework) is added to our test project.
• Add reference of our CustomerOrderService class library to test project.
• Choose add reference in test project -> Project - Solution tab -> Mark the
checkbox before the CustomerOrderService -> Click on OK button.
SEN 461L - Software Testing Lab by Aroosa Hameed 13
15. NUnit Setup (Configuring TestRunners)
• For setup TestRunners, we need to add Nunit Test Adapter from NuGet packages.
Follow the below steps:
1. Right click on CustomerOrderService.Tests and choose 'Manage NuGet
Packages'
2. Choose NUnit3TestAdapter and click on Install button.
SEN 461L - Software Testing Lab by Aroosa Hameed 15
17. NUnit
Test Case:
A set of statements executed by a tester to determine if the program
under test behaves as expected.
SEN 461L - Software Testing Lab by Aroosa Hameed 17
19. NUnit
• Test case is composed of three parts
• Test Data
• Test Sequence
• Test Oracle
SEN 461L - Software Testing Lab by Aroosa Hameed 19
20. NUnit
SEN 461L - Software Testing Lab by Aroosa Hameed 20
• Test data is :
• A set of values, one for each input variable
• Input given to a software program
22. NUnit
SEN 461L - Software Testing Lab by Aroosa Hameed 22
• Order of execution of test case is Test sequence.
• Test oracle:
The entity that perform task of checking correctness of observed
behavior.
24. NUnit
SEN 461L - Software Testing Lab by Aroosa Hameed 24
You have to develop a small program that reads three integer values
from console. The three values represent the lengths of the sides of a
triangle
The program first checks if the triangle is valid. Condition for valid
triangle:
• Sum of any two sides should be greater than the third side
Write a set of test cases to properly test the program