introduction of unit test to management
DESCRIPTION
An introduction of unit test and its benefits to business and managementTRANSCRIPT
Introduction of Unit Test to Management and Business
August, 2012
Wei Li
”To err is human;
to forgive, divine.”
Alexander Pope
Developer Test
– Unit Test
– Integration Test
– Regression Test
QA Test
– Integration Test
– Regression Test
– Performance Test
– Stress Test
Customer/User Test
– Acceptability Test
– Usability Test
Many Tests in the Life Cycle of Software Development
What is Unit Test
Self checking or validation to ensure the code work as expected
Developer’s test
Part of construction cycle
Foundation of all other tests
Where Does Unit Test Fit in Life Cycle?
Requirement gathering
Business Design
Technical Design
– Architecture Design
– Technical Design
Construction
– Code and Unit Test
QA Test
Performance Test
User Test
Unit Test Is Not
QA test
Customer/user test
Why?
What? Write code to test code?
No! I don’t have time for it!
Benefits of Unit Test – Instant Feedback
Unit test provides the earliest opportunity to identify and fix a defect
The earlier an error is found, the less expensive it is to fix it
Performed before components are integrated together
Force the developer to write clean and testable code – which leads to less complexity and better design
If your code is hard to be tested, how can it be easily used, maintained and extended?
Benefits of Unit Test – Write Testable Code
Benefits of Unit Test – Establish Safety Net in the Lifecycle
Can be used as part of regression test suite
Provide the green light to refactor old code and make changes
Benefits of Unit Test – Good Way to Work with Legacy/Existing Code
Write unit test to get started understanding legacy code and system
Benefits of Unit Test – Excellent Way to Learn New Language and API
Write unit test cases to learn and try new API
The unit test cases can become reusable knowledge base
Benefits of Unit Test – Excellent Way to Report a Defect
Write a unit test case to report a defect or a bug in the system
Run the same test to verify the defect is fixed
Benefits of Unit Test - Reusability
Write once run forever – reusable and repeatable
Save time long term in the life cycle
Give new team member a good jump start
Unit Test Practice
Planning and estimation - account for the construction time for unit test
Code a little and unit test a little - repeat the cycle until the construction is done
Part of the code review process
Run unit test when trouble shooting issues
Run unit test whenever a change is made
Run unit test whenever is needed
Enjoy the results
Our old friend JUnit is still our best friend
– No new wheel was reinvented
– De facto tool
– Familiarity to most developers
Unit Test Practice
Use a separate unit test project
– Only contain unit test related Java code but test code in other projects
– Run locally and not deployed to application server
Won’t be part of the deployable to application server
– Freedom to write more unit tests
– Save time in testing (no build and deployment)
Unit Test Practice
Unit test coverage – the thorough the better
Unit Test Practice
Just do it and it will become a habit
You will find out you actually have time to write unit test code
You will find out you actually enjoy doing it
Unit Test Practice
Test Driven/Test First Methodology
Write a test case for a new functionality
Run the test and it fails
Write just enough code to make the test pass
Run the test and it passes
Refactor the code to make it better
Repeat the test
Repeat the cycle
Continuous Integration
Get the latest version of the code from source control system
Build/compile the code
Run all unit test cases
Publish the build and test results
Notify the development team for any failure
Repeat the process periodically, for example, once every hour
”To err is developer;
to catch early, unit test.”