Introduction to good practices insoftware developmentTesting &Continuous Delivery 101Nelson Melina
What is Unit Testing ?● An Unit is smallest testable part of sourcecode.● It Can be an entire interface or just a method(OOP).● Unit Testing isolates parts of a software andverify that each parts behave as intended.
What are the benefits of Unit Testing?● You will find potential problems at the earliesttime possible.● You can refactor code without the fear orregression issues.● The tests serve as a design documentationof how a unit is supposed to work.
What are the limits of Unit Testing ?● They only show the presence or absence ofparticular errors● For every line of code written, programmersoften need 3 to 5 lines of test code.● Nondeterministic and multiple threadsalgorithms can not be easily tested.● Rigorous discipline is needed throughout thesoftware development process.
What are the most common tools ofUnit Testing ?● JUnit (framework)● DBUnit (extension of JUnit)● Mock objects frameworks
Mock Objects● They are simulated objects that mimic the behavior ofreal objects in controlled ways● We need to use them when an object :– returns non-deterministic results.– has states that are difficult to reproduce (e.g., a networkerror).– is slow (e.g., a database).– does not yet exist or may change behavior.– would have to include information or methods only fortesting.
What is Integration Testing ?● Occurs after Unit Testing and beforevalidation testing.● Combination of individual software modulesthat will be tested as a group.
The next step towards completeefficiency is Continuous Integration
RepositoryUnit tests ACode ACode BCode CUnit tests BUnit tests CUnit Tests A, B, C& Integration Tests(A + B + C)Module A (Wallet)Module B (Widget)Module C (MAV)Feedbacks (Alerts,Information, Errors orStatuses) via email towhom is concerned.Continuous Integration Server(Hudson)Is the aggregatebehaving well ?
Here are the key principles of CI● Maintain a code repository.●Automate the build.●Make the build self-testing.●Everyone commits every day.● Every commit should be built.●Keep the build fast.●Test in a clone of the production environment.●Make it easy to get the latest deliverables.● Everyone can see the results of the latest build.●Automate deployment.
Advantages of ContinuousIntegration● When unit tests fail, developers can revert to a bugfree state.● Integration problems and problematic changes arecontinuously detected and fixed.● Immediate feedback to developers.● Frequent code commits pushes developers to createmodular and less complex code.● Metrics generated from automated testing and CI.
The final goal is to achieveContinuous Delivery
Why would we change our way ofworking ?● Reduce current and future costs– Without an automated process, developers lose a great amountof time testing manually the features they program.– The latter we find a bug, the more expensive it is to fix.*● Reduce risks– It is impossible to guaranty that all manually executed test willalways be thorough and accurate.