0% found this document useful (0 votes)
57 views30 pages

CS1702 11.1 Testing v3 (2023-2024)

This document discusses software testing and different types of testing approaches. It covers: - The purpose of software testing is to show that a system meets specifications and performs intended tasks correctly. Testing can find errors but not prove their absence. - Types of testing include white box, black box, gray box, test-driven development, regression, and unit testing. - Specific testing approaches like JUnit for unit testing Java code in Eclipse are also mentioned. The document provides explanations and examples of different testing techniques.

Uploaded by

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

CS1702 11.1 Testing v3 (2023-2024)

This document discusses software testing and different types of testing approaches. It covers: - The purpose of software testing is to show that a system meets specifications and performs intended tasks correctly. Testing can find errors but not prove their absence. - Types of testing include white box, black box, gray box, test-driven development, regression, and unit testing. - Specific testing approaches like JUnit for unit testing Java code in Eclipse are also mentioned. The document provides explanations and examples of different testing techniques.

Uploaded by

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

CEDPS - Department of Computer Science

CS1702 Introductory Programming


(2023-2024)

Dr Stephen Swift

11.1 Testing (and Review of Term)


Previously on CS1702…
CEDPS - Department of Computer Science

 We are learning how to program in this module


 Using Eclipse and Java
 This term we looked at:
Terminology and introductory concepts
Variables

Conditional Statements

Loops

Objects

Arrays

Built in Functions and Methods

User Defined Functions and Methods

Debugging and Exception Handling

Robust Software Development

Testing Slide 2
YourVoice!
CEDPS - Department of Computer Science

 The YourVoice survey [should be] is now available…


What is it?
Why should you complete it?

What do we do with the results?

Who benefits?

How should you complete it?

Testing Slide 3
Preamble…
CEDPS - Department of Computer Science

In this lecture we are going to look at testing


Some of the material we will be discussing will be

covered by Professor Steve Counsell as part of his 4


lectures on OO and OOP
His discussion about testing will be from an OO

perspective…

Testing Slide 4
Why The Fuss About Testing?
CEDPS - Department of Computer Science

Testing has been mentioned many, many times...


So why the fuss?

We have mentioned [so] many times that most development effort is not in

writing code but debugging code


This is usually because rigorous testing has not been carried out
If you do not test your program properly it will simply not work!

Testing Slide 5
Software Testing – Part 1
CEDPS - Department of Computer Science

 The purpose of software testing is to try and:


Show that a software system meets the specification
Demonstrate that the system performs all of the intended tasks as

expected
Show that it runs bug free

Assure the user that it is

what they wanted

Testing Slide 6
Software Testing – Part 2
CEDPS - Department of Computer Science

Testing can never show the absence of errors, only the


presence of them
The aim therefore of any testing strategy is to uncover these

errors
Two areas of testing:

Validation

Making sure you are building the right product


Verification

Making sure you are building the product right
Covered in another module…

Testing Slide 7
Types of Testing
CEDPS - Department of Computer Science

White Box Testing


Black Box Testing

Grey [Gray] Box Testing

Test Driven Development

Regression Testing

Unit Testing

Testing Slide 8
White Box Testing
CEDPS - Department of Computer Science

Test cases are written using knowledge of the


source code and structure of the system being
tested

Test Cases Verify Results/Output

Testing Slide 9
Black Box Testing
CEDPS - Department of Computer Science

Test cases are written without any knowledge of


the source code and structure of the system being
tested

Test Cases Verify Results/Output

Testing Slide 10
Grey [Gray] Box Testing
CEDPS - Department of Computer Science

Test cases are written using some knowledge of


the source code and structure of the system being
tested

Test Cases Verify Results/Output

Testing Slide 11
Does Knowledge Matter?
CEDPS - Department of Computer Science

If you know how the code is designed and/or


structured, test cases can be specifically designed
For example, if a program uses short variables
internally, then it might not work with large inputs
etc…

Testing Slide 12
Regression Testing
CEDPS - Department of Computer Science

Rerunning black box and white box tests after


changes have been made to a software system
Don’t just create new test cases
Should the system pass the previous test cases?

Testing Slide 13
Unit Testing
CEDPS - Department of Computer Science

The testing of the smallest possible part of a


software system
E.g. methods

Testing Slide 14
JUnit – Part 1
CEDPS - Department of Computer Science

Java/Eclipse has a built in unit testing framework called


JUnit
The aim of this framework is to make unit testing easier to

design and manage


Let us assume we have a class called UselessAlgorithm

with method ComputeUselessAlgorithm to test


We can create a unit test program to test this class

Testing Slide 15
JUnit – Part 2
CEDPS - Department of Computer Science

 Here is our class and method we wish to unit test:


public class UselessAlgorithm
{
public static int ComputeUselessAlgorithm(int x)
{
int y = x + 1;
return(y);
}
}

Testing Slide 16
The JUnit Class – Part 3
CEDPS - Department of Computer Science

 We choose Eclipse menu


items:
File->New->JUnit Test Case
to create a new JUnit test
Select JUnit version 4
We select the source folder of
where the code we wish to test
resides
We then need to name the new

class that we are creating the


tests within
This new test class will be

placed in the same place as the


code we wish to test

Testing Slide 17
The JUnit Class – Part 4
CEDPS - Department of Computer Science

JUnit works by running predefined code (methods) at


particular points within the test
This code is defined by us and is completely dependant on

the context of the test


The points and times that these methods are run are

indicated by using macros starting with the @ symbol

Testing Slide 18
The JUnit Class – Part 5
CEDPS - Department of Computer Science

 @BeforeClass
The proceeding method is run before the test class is created
E.g. you may want to create some data for all of the tests

 @Before
The proceeding method is run before each test method is run
E.g. you may want to perform some tasks specific to the test

 @Test
 The proceeding method is a test
 @After
The proceeding method is run after each test method is run
E.g. clearing up test specific data

 @AfterClass
The proceeding method is run after the test class is created
E.g. clearing up the data or writing results to a file

Testing Slide 19
The JUnit Class – Part 6
CEDPS - Department of Computer Science

import org.junit.*;
This import
is needed
public class UselessAlgorithmTest
{
These are macro instructions
@BeforeClass to the Eclipse IDE (@)
public static void BeforeClass() throws Exception
{
System.out.println("+++In BeforeClass");
}
@Before
public void BeforeTest() throws Exception
{
System.out.println("+++In BeforeTest");
}
@Test Call to the
public void ATest() class we
{ are testing
System.out.println("+++In ATest");
System.out.println(UselessAlgorithm.ComputeUselessAlgorithm(4));
}
...

//See next slide…

Testing Slide 20
The JUnit Class – Part 7
CEDPS - Department of Computer Science

//Continued from last slide... Call to the


@Test class we
public void AnotherTest()
are testing
{
System.out.println("+++In AnotherTest");
System.out.println(UselessAlgorithm.ComputeUselessAlgorithm(21));
}
@After
public void AfterTest() throws Exception
{
Output:
System.out.println("+++In AfterTest");
} +++In BeforeClass
@AfterClass +++In BeforeTest
public static void AfterClass() throws Exception
{
+++In ATest
System.out.println("+++In AfterClass"); 5
} +++In AfterTest
public static void main(String args[])
{
+++In BeforeTest
UselessAlgorithmTest jut = new UselessAlgorithmTest(); +++In AnotherTest
22
jut.ATest();
jut.AnotherTest();
+++In AfterTest
} This is how +++In AfterClass
} the tests are
executed
Testing Slide 21
The JUnit Class – Part 8
CEDPS - Department of Computer Science

 Example…

Testing Slide 22
Test Driven Development – Part 1
CEDPS - Department of Computer Science

Test Driven Development (TDD) is a systematic approach


to testing
This approach is an iterative procedure:
Firstly, design a small set of code that tests some functionality
Develop production code that fulfils the test criteria

Once the production code has passed the test, refactor the code

Testing Slide 23
Test Driven Development – Part 2
CEDPS - Department of Computer Science

Add a
Start test that
fails

(Re)Write
some
code
No

Development Yes
Run all End
tests complete?

No Yes Refactor
All tests
passed? code

Testing Slide 24
Test Driven Development – Part 3
CEDPS - Department of Computer Science

The tests that are required should arise from the project
specification/design
Often the test code is as large as the actual production code!

More information can be found at:

http://www.agiledata.org/essays/tdd.html

Testing Slide 25
Test Driven Development – Part 4
CEDPS - Department of Computer Science

 So what is refactoring?
This will be covered in detail in term 2…
Consider it to be modifying a section of code
So that it does not change what it does
But the code is “better”…

 What is “better”?

Testing Slide 26
Test Driven Development – Part 5
CEDPS - Department of Computer Science

There is much more to this topic!


The initial concepts are straightforward

We suggest that this is the procedure you follow when

developing code
Design your testing plan before you start working on the

code...

Testing Slide 27
Testing Guidelines
CEDPS - Department of Computer Science

 Create lots and lots of test cases


Cover all possibilities
Including nonsense data!

Are exceptions handled?


If the input to a method is an object:
 Pass in null
 If the input is an array:
Pass in null
Pass in an empty array

Testing Slide 28
Next Term…
CEDPS - Department of Computer Science

 Term 2…
CS1702 INTRODUCTORY PROGRAMMING WEEKLY SCHEDULE (2023-2024)
Lectures [In Person] Laboratory (Various Times)
Week# Term 2: 11:00-12:00 (ESGW)
Subject Assessed?
17 12. OO 1 – Basic Concepts, User Defined Classes Catch Up Laboratory No
18 13. OO 2 – Containers, Templates, Patterns Catch Up Laboratory Maybe!
19 14. OO 3 – Attributes and Methods Catch Up Laboratory Maybe!
20 15. OO 4 – OO Principles and Testing Catch Up Laboratory, CODERUNNER Deadline Yes!
21 16. Further Algorithms Graphical User Interfaces No
22 Reading Week – No lecture N/A N/A
23 17. Big Data and AI Basic Web Scraping No
24 18. Module Summary Catch Up Laboratory Maybe!
25 No Lecture Task#3 vivas – No laboratories Yes!
26 No Lecture Catch Up Laboratory - Exam Preparation Maybe!
27 No Lecture Catch Up Laboratory - Exam Preparation Maybe!
31 No Lecture Catch Up Laboratory - Exam Preparation Maybe!

Testing Slide 29
Next Topic
CEDPS - Department of Computer Science

 The next topic we will look at is:


The basic concepts on Object Oriented programming
Week 17 – next term!

This will be delivered by:


Professor Steve Counsell

 The laboratory:
A worksheet on testing
 Also:
Remember YourVoice!
Have a top Xmas and NY!

Testing Slide 30

You might also like