ENGG1810/9810
ENGG1810/9810
Introduction to Engineering Computing
Week 10: Application II
Dr. Imdad Ullah
Faculty of Engineering
ENGG1810/9810
COMMONWEALTH OF AUSTRALIA
Copyright Regulations 1969
WARNING
This material has been reproduced and communicated to you by or on behalf of
the University of Sydney pursuant to Part VB of the Copyright Act 1968 (the Act).
The material in this communication may be subject to copyright under the Act.
Any further reproduction or communication of this material by you may be the
subject of copyright protection under the Act.
Do not remove this notice.
INTRODUCTION
ENGG1810/9810
What will you learn in this course?
Week 1: Introduction to Python
Week 2: Storing Data and Making Decisions Programming
Week 3: Repeating Actions I Basics
Week 4: Repeating Actions II
ft
Week 5: Functions I
f
Week 6: Functions II Functions
Week 7: Libraries and Modules I
and Packages
Week 8: Libraries and Modules II
Week 9: Application I
Week 10: Application II Advanced
Week 11: Case Study I
Topics
Week 12: Case Study II
Week 13: Revision and Exam Guide
ENGG1810/9810
Today’s Lecture
• LabTest 2 Guide
• Assessment Details
• Question Types and Sample Questions
• Testing Your Code
• Manual Testing
• Automatic Testing
• Python unittest
• TestCase
• Assertion
• Check the process time
ENGG1810/9810
LabTest 2 Guideline
We will go through the Lab Test 2 Guideline and sample Qs during the Lecture
Please join the lecture and ask Questions
ENGG1810/9810
Today’s Lecture
• LabTest 2 Guide
• Assessment Details
• Sample Questions
• Testing Your Code
• Manual Testing
• Automatic Testing
• Python unittest
• TestCase
• Assertion
• Check the process time
ENGG1810/9810
What makes a code good?
How??
ENGG1810/9810
Class ShoppingCart
a to b 2 C
aname for each object
Imig
a atb
Add a new item then
to the list a t C B
Calculate the
total cost
g
ENGG1810/9810
Class ShoppingCart
Add a new item
to the list
How can we check
whether the code is
working smoothly or not?
Calculate the
total cost
ENGG1810/9810
Class ShoppingCart
Execute codes (from Week 1)
Code Tracing/ Desk Checks (from Week 2)
How can we check
whether the code is
working smoothly or not?
Exception Handling (Week 6)
ENGG1810/9810
Class ShoppingCart
With Script
Importing
createdinstant avec fruition
nothing
added
3addingitems
Milk 2x5
1 7
yogurt
D
ENGG1810/9810
Class ShoppingCart
With Script – Manual Testing
To have a complete set of manual tests, You
need to make a list of:
1) all the features your program has,
2) the different types of input it can accept,
3) and the expected results
Very exhausting…
ENGG1810/9810
Today’s Lecture
• LabTest 2 Guide
• Assessment Details
• Sample Questions
• Testing Your Code
• Manual Testing
• Automatic Testing
• Python unittest
• TestCase
• Assertion
• Check the process time
ENGG1810/9810
Automated Testing (like Cars)
Cars tell you when your engine has an issue.
It does this using a form of automated test.
It checks that each component operates in the right way.
ENGG1810/9810
Automated Testing
Automated testing is the execution of your test plan (the parts of
your program you want to test, the order in which you want to test
them, and the expected responses) by a script instead of a human.
Python already comes with a module called unittest
to help you create automated tests for your program.
To use it, we can use the keyword import module:
import unittest automat
testing
unittest Reference
https://docs.python.org/3/library/unittest.html
ENGG1810/9810
Today’s Lecture
• LabTest 2 Guide
• Assessment Details
• Sample Questions
• Testing Your Code
• Manual Testing
• Automatic Testing
• Python unittest
• TestCase
• Assertion
• Check the process time
ENGG1810/9810
What makes a code good?
Test Driven
Development
A way of software development that requires
you to write the tests for a given function first,
before you even write the function!
ENGG1810/9810
Python unittest
import unittest
unittest contains both a testing framework and a test runner.
It requires that:
• You put your tests into classes as methods
• You use a series of special assertion methods in the unittest.TestCase class
Test Case Test Suite Test Runner
Individual unit of testing. A collection of test cases, test It orchestrates the execution of
Checks for a specific response suites, or both. It aggregates tests and provides the
to a particular set of inputs tests that should be executed outcome to the user
ENGG1810/9810
Python unittest
import unittest
unittest contains both a testing framework and a test runner.
It requires that:
• You put your tests into classes as methods
• You use a series of special assertion methods in the unittest.TestCase class
Test Case
Test Case Test Suite Test Runner Test Report
Test Case
ENGG1810/9810
Class A if say liars B
floss Binherit ClassA
Van IA Python unittest
Vana
Meth I arm
meth2 Math B
Create a class called TestShopping that
inherits from the TestCase class
O Sittefanon
hotestcaseednIa caimatenuane
Gate's.EE Use the test functions(methods)
by adding self as the first argument
xp
ENGG1810/9810
Python unittest
Create a class called TestShopping that
inherits from the TestCase class
Apply assertions by using the
self.assertEqual()method
on the TestCase class
ENGG1810/9810
Python unittest
Create a class called TestShopping that
inherits from the TestCase class
Test Runner:
This is a command line entry point.
It means that if you execute the script alone by running Python unittest_ex1.py
at the command line, it will call unittest.main(). This executes the test runner by
discovering all classes in this file that inherit from unittest.TestCase.
ENGG1810/9810
Python unittest
Let’s execute the script
ENGG1810/9810
Python unittest: assert method
unittest comes with lots of methods to assert
on the values, types, and existence of variables.
unittest Method Checks that
assertEqual(a, b) a == b
assertNotEqual(a, b) a != b
assertTrue(x) bool(x) is True
assertFalse(x) bool(x) is False
assertIn(a, b) a in b
assertNotIn(a, b) a not in b
assertGreater(a, b) a > b
assertGreaterEqual(a, b) a >= b
assertAlmostEqual(a, b) round(a-b, 7) == 0
assertNotAlmostEqual(a, b) round(a-b, 7) != 0
https://docs.python.org/3/library/unittest.html#assert-methods
ENGG1810/9810
Python unittest
Is this enough?
ENGG1810/9810
Python unittest
ENGG1810/9810
Python unittest: failed cases
ENGG1810/9810
Python unittest: multiple test cases
ENGG1810/9810
Python unittest: failed cases
ENGG1810/9810
Python unittest: select the case
Select only Test method that you want
ENGG1810/9810
Today’s Lecture
• LabTest 2 Guide
• Assessment Details
• Sample Questions
• Testing Your Code
• Manual Testing
• Automatic Testing
• Python unittest
• TestCase
• Assertion
• Check the process time
ENGG1810/9810
Python Process_time
You can also check the processing time using time module
https://docs.python.org/3/library/time.html#time.process_time
ENGG1810/9810
Python Process_time
You can also check the processing time using time module
https://docs.python.org/3/library/time.html#time.process_time
ENGG1810/9810
Python Process_time
Let’s have a look how we can check the process time of the multiple files/modules
Let’s go through with Caren
(during the lecture)
https://docs.python.org/3/library/importlib.html
https://docs.python.org/3/library/glob.html
https://docs.python.org/3/library/os.html
ENGG1810/9810
Python Process_time
Let’s have a look how we can check the process time of the multiple files/modules
system
Let’s go through with Caren
ofpii
system
(during the lecture)
inside
going
folders
https://docs.python.org/3/library/importlib.html
https://docs.python.org/3/library/glob.html
https://docs.python.org/3/library/os.html
ENGG1810/9810
THANKS FOR
WATCHING
Good luck in studying