Awat Z. Hamad Unit Testing and Mocking

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Unit Testing & Mocking

Prepared by

Awat Z. Hamad

Emerging Technologies
Under Supervision
Assistant Prof. Dr. Rebwar M. Nabi

Academic Year 2021-2022


Outline

Aims
To introduce Unit test and mocking in software development

Presentation Objectives

• Understanding the project development cycles


• Explaining Unit test and Mocking
• Explaining the demo project
Software Development Life Cycle (SDLC)

Today, we are focusing on Test


What is testing?

Testing is an example of a more general process called validation.

Input
Testing: Running the program on carefully selected inputs
and checking the results.
Process

Output

Measure twice, cut once


What is mocking?

Mocking is a process used in unit testing when the unit being tested has external dependencies.

Mocking

Developer 1 Developer 2

Function Add Function Sum

Function Add
Unit Testing Advantage & Disadvantages

Advantage

• Unit testing improves the quality of the code.


• Issues are found at an early stage.
• Helps reduce the cost of bug fixes.
• Due to the modular nature, we can test parts of the project without waiting for others to
be completed.

Disadvantages

• Unit testing can’t be expected to catch every error in a program.


• Unit testing by its very nature focuses on a unit of code.
Unit Testing Best Practices

• Unit Test cases should be independent.

• Test only one code at a time.

• Follow clear and consistent naming conventions for your unit tests

• Bugs identified during unit testing must be fixed before proceeding to the next phase in SDLC

• Adopt a “test as your code” approach.


Unit Test tools

NUnit https://nunit.org/
JUnit https://junit.org/junit5/

MSTest
https://docs.microsoft.com/en-us/visualstudio/test
xUnit

UnitTest

PHPUnit https://phpunit.de/
Summary

• The purpose of using SDLC is to develop a stable and reliable software

• Unit Test a type of software testing where individual units or components of a software are tested

• Unit testing is very important to learn if you want to develop complex software products

• Mocking is very useful concept when the project is distributed among many team members
Any questions about our subject?

Any new suggestions are welcome

You might also like