View
62
Download
0
Category
Preview:
Citation preview
About my company:
• Founded: Oct/2003 • Headquarter: Tokyo • Services: Web & Smartphone
development • Number of employees: 60 SeeSaa
Tokyo
Viet Nam
Kyoto
Agenda: What is Unit Test ?
Why should we do Unit Test ?
When, Where & Who do Unit Test ?
How to write a good Unit Test
Unit Test
Unit Tes)ng is a process of wri)ng test for specific part of code/system.
A Unit is the smallest possible part of
applica)on/system under test.
Tes)ng is a process of
checking/evalua)ng an aJribute/characteris)cs/
capability of a method/object/program…
and determining that actual behavior meets with expected
behavior.
Why should we do Unit Test ?
• How about Logger, Debugger ?
Faster debugging, isn’t it ?
• Not sure, even slower! Faster development, isn’t it ?
• Let see an example:
Faster tes)ng ?
Why should we do Unit Test ?
• Instead of wri)ng code to do something, you’re star)ng by outlining all the condi)ons you’re subjec)ng the code to and what outputs you’d expect from that
Designing soUware components robustly
• Avoid regression errors • You test the code once and the con)nuously aUerwards • For people who are going to maintain or develop your code
Reduce future code
• Of course, are developers
Who create Unit Test ?
• Right aUer get & read details design/requirement.
Where in project development ?
• Depends on size of the project ? • Depends on kind of the project ? • Depends on level of the developer ?
When do, when don’t ?
• Process: • Get & Read detail design document • Choose a function to develop, then follow
to the diagram • Take attention: whenever refactoring your
code, you should run unit test accordingly. Along with adding new code, you need to perform corresponding tests as well.
How to write a good Unit Test
Structure: • Set up all conditions for testing • Call the method (or trigger)
being tested • Verify that the result is correct • Teardown: clean up modified
records
How to write a good Unit Test
Some tips: • Make each test independent to all the
others • Test one thing only in one test case • One function may have multiple unit
tests according to the usage and outputs of the function
• Don’t forget to refactor the test code • With little time and much to test you can’t
afford lengthy and ineffective checks. Make test case simple, concentrate on the core behavior of your product and use as little code as you can.
• Creating maintainable & readable tests
How to write a good Unit Test
Recommended