0% found this document useful (0 votes)
32 views4 pages

Info632 TD1

Uploaded by

joseph Ewondjo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Info632 TD1

Uploaded by

joseph Ewondjo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

RÉPUBLIQUE DU CAMEROUN REPUBLIC OF CAMEROON

Paix – Travail – Patrie Peace – Work – Fatherland


-.-.-.- -.-.-.-
UNIVERSITÉ DE YAOUNDÉ I UNIVERSITY OF YAOUNDÉ I
Faculté des Sciences Faculty of Science
Département d'Informatique Department of Computer
Science

INFO 362: Software Testing


(Dr KIMBI Xaveria)

TD 1 : Getting started with Unit Testing

You are part of a team developing a new mobile application for a local restaurant. The
application aims to allow users create a basket of products and get promotions. As the
project progresses, your team has completed the initial development phase and is now
entering the testing phase.

Your Role:

As a software tester on the team, your role is crucial in ensuring the quality and reliability of
the application before it is released to the public. Your main responsibilities include:

1. Test Case Development: Based on the test plan, you will develop detailed test cases
covering various scenarios and functionalities of the application. This includes
positive tests to validate expected behavior and negative tests to uncover potential
bugs and vulnerabilities.
2. Execution of Test Cases: You will execute the test cases systematically, recording
the results and any issues encountered during testing. This will involve testing the
application on different devices, operating systems, and network conditions to
ensure compatibility and robustness.

To quickly get to grips with the project, the team asks you to take a copy of the project on the
following link. https://github.com/atemengue/software_testing_labs

Level 1: the first level will consist of writing simple tests for the intro.js, core.js files. the
aim is for you to get to grips with the vitest framework for writing application tests. it's
important to get members of the development team involved in building application tests.

NodeJS version: 20.11.0

Make sure you have this version to follow the project.

1
1 – Introduction of Unit Testing
Automated testing involves writing code to verify that our software behaves as
expected. When done properly, it can significantly reduce the need for and cost of
manual testing. However, it cannot entirely replace manual testing, as certain aspects of
an application (e.g., aesthetics) are best assessed by human testers.

● Exercice: Writing Your First Tests


○ Write unit testing of max function in the intro.js.
○ Refactor the max function

Test structures often follow the AAA (Arrange-Act-Assert) pattern. During the
Arrange phase, we set up the test environment. In the Act phase, we perform the
action to be tested, and in the Assert phase, we validate the outcome against our
expectations.

● Test Driven Development

Test-driven Development (TDD) is a development approach where tests are written


before the corresponding code is implemented, promoting a clear development
process and well-tested code.
Exercice:
○ Discussion about Test Driven Developement
● Charecteristiques of Good Unit Test

It's better not to write tests than to write bad tests; good tests should be easy to
maintain, reliable, and trustworthy.

To make your tests easier to maintain, give them clear names, focus on testing one thing
at a time, and keep them short and well-organized.

Effective tests are robust and don’t break easily when you make small changes to your
code, as long as the main functionality remains the same. To achieve this, test what the
code should do, not how it does it. In other words, test the behavior, not the
implementation.

Tight assertions can result in fragile tests that frequently break, while loose assertions can
lead to tests that consistently pass (false positives) and fail to provide us with enough
confidence that our software works. Striking the right balance between loose and tight
assertions is crucial for effective testing.

Tests should not be dependent on random values, current date/time, or any global
state, as this can cause them to give different results each time they are run.

● Exercice: Complete your unit testing.


○ Write the unit tests for the code in the intro.js file
○ Write good assertions getCoupons function. in core.js file

2
2 – Core Unit of Unit Testing
● Using Matchers

A matcher is a function (or method) that allows us to make assertions about the
values produced during testing. Examples are toBe, toEqual, toBeNull, etc.
Check Common Matchers at the end of document.

Exercice: Using Matchers.


■ toBe()
■ toEqual()
■ toBeTruthy()
■ toBeUndefined()
■ toMatchObject()
■ toHaveProperty()
■ toContain()

● Writing Good Assertions

Exercice: use a case study of your choice

● Positive and Negative Testing

Positive tests make sure that our application works under normal conditions, while
negative tests check how it handles unexpected or invalid input.

Exercice: Write Unit Testing for CalculateDiscount function. in core.js file

● Boundary Testing

Boundary testing is when we test how our software behaves in extreme situations
or at the edges of what it can handle.

Exercice: Apply Boundary Testing on isPriceInRange and


isValidUsername function. in core.js file

● Parameterized Tests

Parameterized tests, also known as data-driven tests, are a testing technique where a
single test case is executed multiple times with different sets of input data or
parameters.

Exercice: use a case study of your choice for Parameterizes Tests.

3
Common Matchers

Equality

toBe()
toEqual()
Truthiness
toBeTruthy()
toBeFalsy()
toBeNull()
toBeUndefined()
toBeDefined()

Numbers
toBeGreaterThan()
toBeGreaterThanOrEqualTo()
toBeLessThan()
toBeLessThanOrEqualTo()
toBeCloseTo()

Strings
toMatch()
Objects

toMatchObject()
toHaveProperty()
Arrays

toContain()
toHaveLength()

You might also like