Software Testing

Testing Pyramid

Instructor: Chris Fulton

Learning Objectives

  • Software Testing
    • Why is software testing important?
    • System Development Life Cycle(SDLC)
    • Functional vs. Non-Functional Testing
  • Types of Test
    • Unit Testing Node.js - Using Jest Testing Framework
    • Integration Testing
    • End to End Tests
    • UI Tests
  • Software Automation Tools
    • Selenium
    • Webdriver.io
Why is software testing important?

Detect Logical Errors and Bugs

📢 Catch mis-calculations
📢 Enforce proper authentication
📢 Proper handling of exceptions

Quality Control and Security

📢 Efficient Code Integration and Continous Integration
📢 Enforce Code Quality

Cost Savings

📢 Prevention Measures for erraneous code
📢 Decreases Malfunction
📢 Reduces Human Resouce Cost for remediation

End-User Satisfaction

📢 Enhances Usability
📢 Increases Adoption
📢 Elevates Competitive Advantage

Understanding SDLC

What do we test and how do we know what to test? We start with the system development life cycle (SDLC). This SDLC informs us on what we are going to test and what are critical requirements defined by the client.

image of system development life cycle

SDLC Process and responsibility

image of system development life cycle responsibility breakdown

SDCL Brief Overview

Functional vs. Non-Functional Test

A number of functional and non-functional test can be completed using tools that allow for automation vs. manually testing even non-functional test.

Functional vs Non-functional software test

Unit Testing

Write tests until fear is transformed into boredom.

Node.js Unit Testing Frameworks

Node.js Testing Frameworks - Some are opininated and some are catered toward other frameworks.
Stateofjs.com testing framework rankings

jest test framework logo
jasmine test framework logo
Mocha test framework logo

Crafting a Unit Test

The purpose of the test to ensure that the unit of code is properly functioning as intended. Some would encourage test-driven development to enforce compliance.

① Understand Testing Platform
Select an a unit testing platform and understand the stucture of test and the configuration of such test

② Determine Goals of Unit Test
Define what the purpose of the test/test suite should be. Identify what the test will accomplish. What will a fail notification tell us? Why will this test put our team at ease?

③ Define boundaries of test
Define what the test will measure. You can have multiple test for a method. What you identify as the boundaries is what you will include in the output of the test.

④ Determine Inputs/Outputs
Decide on preset data that will accurately measure what you defined as boundaries. What should the test return, do we need multiple expectations to ensure accuracy.

Crafting a Unit Test Example

Simple Arithmetic function that adds two numbers together and returns sum

❶ Understand Testing Platform
- Jest Testing Framework

❷ Determine Goals of Unit Test
- The goal is to ensure that that two interger values return the sum

❸ Define boundaries of test
- Returns the sum of two numbers; The sum is less than 30

❹ Determine Input/Output
- First Value will be 2 and second value will be 3. and the sum will equate to 5; The sum is less than 30 given two arguments from extenal file.

Unit Test Activity 1

① Create a project and create a package.json file, index.js file and sum.js file

② Install jest test framework as a dev dependency

③ Alter the package.json file

④ Add the following code to sum.js file

⑤ Import the sum.js file into your index.js file and call the add function and output returned value to console.

⑥ Create the unit test(s) that will test if the numbers are added


npm init
									
								

npm install --save-dev jest
									
								

{
  "scripts": {
    "test": "jest"
  }
}
									
								

function sum(a, b) {
  return a + b;
}
module.exports = {sum};
									
								

const sumModule = require('./sum.js');

var total = sumModule.sum(2,3);
console.log(total);
									
								

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum.sum(1, 2)).toBe(3);
});
									
								

Activity 2

For this activity, please refer to the previous slide on project structure

						
							function getFavoriteNum(favNum){
							    var enteredNum = favNum;
							    return favNum;
							}
							
							module.exports = {getFavoriteNum};
						
					

Step 1
→ Create a project folder
→ Using the function above, add the function to a file and make sure the function can be used in other files.

Step 2
→ Create a index.js file and make the getFavoriteNum function availabe to the index.js file
→ Call the getFavoriteNum function and pass in a favorite number that's between 1 and 100.
→ Output the returned value from the method to console
→ Run the program.

Step 3
→ Create a test file
→ Create a unit test that enforces a value between 1 and 100
→ Create a test enforces a value that is not between 1 and 100
Hint - Make sure to select the correct expect method. Jest expect resource

Integration Testing

What is Integration Testing

Integration tests determine if independently developed units of software work correctly when they are connected to each other. More often than not, the focuses is on the flow of data between modules

Integration testing visual illustration

Overview of Integration Testing

Resource from guru99

Integration Testing Process

1. Prepare the test integration plan. Sample Integration Test Plan

2. Decide on the type of integration testing approach

3. Design test cases, test scenarios and test scripts accordingly.
A test case is a document which has a set of conditions or actions that are performed on the software application in order to verify the expected functionality of the feature.

4. Deploy the chosen modules together and get the integration tests running

5. Track the defects and record the test results of tests

6. Repeat the above steps until the complete system is tested

Types of Integration Testing

Big Bang Integration Testing
all the modules are developed and tested individually, they are integrated once and tested together at once. The only advantage of this type of testing is that it is very much suitable for smaller systems.

Incremental Integration Testing
is performed by connecting two or more modules together that are logically related. Later more modules are added and tested for proper functionality. This is done until all the modules are integrated and tested successfully. It’s further divided into Top-Down Approach and Bottom-Up Approach

Top-Down Integration Testing
starts by testing the top-most modules and gradually moving down to the lowest set of modules one-by-one.

Bottom-Up Integration Testing
starts with testing the lowest units of the application and gradually moving up one-by-one.

End-to-End Testing

End-to-End Testing Frameworks

End-to-End Testing test an application flow from start to end. The purpose of End to end testing is to simulate the real user scenario and validate the system under test and its components for integration and data integrity. The purpose of end-to-end Test is to exercise a complete production-like scenario. Focuses on simulation and interface interaction.

jest and puppeteer logo
selenium logo
test cafe logo
taiko logo

References

  • https://medium.com/@nathankpeck/microservice-testing-unit-tests-d795194fe14e
  • https://www.edureka.co/blog/what-is-integration-testing-a-simple-guide-on-how-to-perform-integration-testing/