CS1702 11.1 Testing v3 (2023-2024)
CS1702 11.1 Testing v3 (2023-2024)
Dr Stephen Swift
Conditional Statements
Loops
Objects
Arrays
Testing Slide 2
YourVoice!
CEDPS - Department of Computer Science
Who benefits?
Testing Slide 3
Preamble…
CEDPS - Department of Computer Science
perspective…
Testing Slide 4
Why The Fuss About Testing?
CEDPS - Department of Computer Science
We have mentioned [so] many times that most development effort is not in
Testing Slide 5
Software Testing – Part 1
CEDPS - Department of Computer Science
expected
Show that it runs bug free
Testing Slide 6
Software Testing – Part 2
CEDPS - Department of Computer Science
errors
Two areas of testing:
Validation
Verification
Making sure you are building the product right
Covered in another module…
Testing Slide 7
Types of Testing
CEDPS - Department of Computer Science
Regression Testing
Unit Testing
Testing Slide 8
White Box Testing
CEDPS - Department of Computer Science
Testing Slide 9
Black Box Testing
CEDPS - Department of Computer Science
Testing Slide 10
Grey [Gray] Box Testing
CEDPS - Department of Computer Science
Testing Slide 11
Does Knowledge Matter?
CEDPS - Department of Computer Science
Testing Slide 12
Regression Testing
CEDPS - Department of Computer Science
Testing Slide 13
Unit Testing
CEDPS - Department of Computer Science
Testing Slide 14
JUnit – Part 1
CEDPS - Department of Computer Science
Testing Slide 15
JUnit – Part 2
CEDPS - Department of Computer Science
Testing Slide 16
The JUnit Class – Part 3
CEDPS - Department of Computer Science
Testing Slide 17
The JUnit Class – Part 4
CEDPS - Department of Computer Science
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));
}
...
Testing Slide 20
The JUnit Class – Part 7
CEDPS - Department of Computer Science
Example…
Testing Slide 22
Test Driven Development – Part 1
CEDPS - Department of Computer Science
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!
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
developing code
Design your testing plan before you start working on the
code...
Testing Slide 27
Testing Guidelines
CEDPS - Department of Computer Science
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 laboratory:
A worksheet on testing
Also:
Remember YourVoice!
Have a top Xmas and NY!
Testing Slide 30