FIT4004 Lecture Notes - Lecture 8: Test Method, List Of Unit Testing Frameworks, Test Stub

23 views2 pages
Lecture 8 - Unit Tesng
Unit :
Small
Self-contained chunks of related funconality
In OOD units are usually Classes
Unit tests :
Wrien by the developers of the unit
Almost always automated
Test method
Paern is :
1. Do something
2. Assert that the results as expected
Do unit tests executes in a parcular order?
No
What method exists to set up a test case?
setup()
What method exists for clean up aer a test?
tearDown()
How would you test that a unit fails as expected?
assertRaises()
Side Eects of tesng code that calls external modules
Tesng code that cells external modules poses several problems:
1. If we find a bug, is it in our module, or the calling module?
2. If we want to rigorously verify the behaviour of the system, the outputs include the side
effects.
3. The outside world can be unpredictable, making it hard to repeat tests
4. You don’t want a system under test interacng with writable, valuable data
5. Wring and reading from the outside world can pose performance problems
Glue code
Code that replaces objects, modules and methods outside of the unit order test
Stubs : empty methods that did nothing but return appropriate dummy data
Fakes: More comprehensive but limited prototype implementaons for tesng that can do
things like check arguments and apply simple logic to determine an appropriate test data
Shim: Intermediate code inserted to check arguments before handing off to the real
exenteral code that did the work
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Wri(cid:425)e(cid:374) (cid:271)(cid:455) the de(cid:448)elopers of the u(cid:374)it. What (cid:373)ethod e(cid:454)ists to set up a test (cid:272)ase? setup(cid:894)(cid:895) What (cid:373)ethod e(cid:454)ists for (cid:272)lea(cid:374) up a(cid:332)er a test? teardo(cid:449)(cid:374)(cid:894)(cid:895) Ho(cid:449) (cid:449)ould (cid:455)ou test that a u(cid:374)it fails as e(cid:454)pe(cid:272)ted? assertraises(cid:894)(cid:895) Side e e(cid:272)ts of tes(cid:415)(cid:374)g (cid:272)ode that (cid:272)alls e(cid:454)ter(cid:374)al (cid:373)odules. Tes(cid:415)(cid:374)g (cid:272)ode that (cid:272)ells e(cid:454)ter(cid:374)al (cid:373)odules poses se(cid:448)eral pro(cid:271)le(cid:373)s: (cid:1005). (cid:1006). If (cid:449)e (cid:449)a(cid:374)t to rigorousl(cid:455) (cid:448)erif(cid:455) the (cid:271)eha(cid:448)iour of the s(cid:455)ste(cid:373), the outputs i(cid:374)(cid:272)lude the side e e(cid:272)ts. (cid:1007). The outside (cid:449)orld (cid:272)a(cid:374) (cid:271)e u(cid:374)predi(cid:272)ta(cid:271)le, (cid:373)aki(cid:374)g it hard to repeat tests (cid:1008). You do(cid:374)"t (cid:449)a(cid:374)t a s(cid:455)ste(cid:373) u(cid:374)der test i(cid:374)tera(cid:272)(cid:415)(cid:374)g (cid:449)ith (cid:449)rita(cid:271)le, (cid:448)alua(cid:271)le data (cid:1009). Wri(cid:415)(cid:374)g a(cid:374)d readi(cid:374)g fro(cid:373) the outside (cid:449)orld (cid:272)a(cid:374) pose perfor(cid:373)a(cid:374)(cid:272)e pro(cid:271)le(cid:373)s. Code that repla(cid:272)es o(cid:271)je(cid:272)ts, (cid:373)odules a(cid:374)d (cid:373)ethods outside of the u(cid:374)it order test. Stubs : e(cid:373)pt(cid:455) (cid:373)ethods that did (cid:374)othi(cid:374)g (cid:271)ut retur(cid:374) appropriate du(cid:373)(cid:373)(cid:455) data.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers