UnderstandingUnit TestingINTRODUCTION TO AUTOMATED TESTING AND UNIT TESTING
Introduction Ikhwan Hayat (a.k.a 1kHz) 9 years experience developingsoftware Freelance Software Developer ikhwanhayat@...
manual3Testing?VSautomatedwhite boxVSblack boxacceptance testintegration testunit test
Unit? 4Unit testing is a method by which individual units ofsource code are tested to determine if they are fit foruse.One...
TDD Test Driven Design It’s NOT testing, but using tests to DRIVE thedesign As a side-effect, you got unit tests!With g...
6REDGREENREFACTORWrite a failing test. With empty class/method.Fill in the class/method implementation. Make the tests pas...
Demo: Bank Account Requirements Can create bank accounts Can deposit money into account Can withdraw money from accoun...
8IDE / Platformhttp://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-webhttps://code.google.com/p/m...
Design 9
10ARRANGEACTASSERT
Unit11Test
12
Design 2 13
14Unit Test
Design 3 15
16repositoryVSactive record???
17Unit Test
A good unit test is… Isolated/independent Test one thing at a time. Unit under test doesn’t depend on the other to make...
19Dependency InjectionSeparation of Interfaceand ImplementationSingle Responsibility Principal
20Web Controller DI/IoC Setup
21“Mocking” allow us toisolate dependentunits.
Types of Test Doubles Dummy objects are passed around but never actuallyused. Usually they are just used to fill paramete...
23Unit Test
Benefits Instant feedback Write test, write code, see instant result. Promote modularity in your design DI, SRP, Inter...
Done! What is unit testing. TDD. How to write good unit tests. How unit testing can benefit us.25We have learned…Get t...
Next? Learning BDD (Behavior Driven Design). Research CI (Continuous Integration). Learn on how to design testable syst...
MOAR! Google+ MyDev http://www.mydev.my/automated-testing-dalam-pembangunan-perisian.html ikhwanhayat@gmail.com27THANK ...
Upcoming SlideShare
Loading in...5
×

Understanding Unit Testing

1,126

Published on

Introduction to automated testing and unit testing

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,126
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
75
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • In procedural -> module/function, In OOP -> class/method. Jenis test paling mendalam. What you actually test is behavior.
  • Create projects
  • Go to codes
  • Go to codes
  • Copy files
  • Understanding Unit Testing

    1. 1. UnderstandingUnit TestingINTRODUCTION TO AUTOMATED TESTING AND UNIT TESTING
    2. 2. Introduction Ikhwan Hayat (a.k.a 1kHz) 9 years experience developingsoftware Freelance Software Developer ikhwanhayat@gmail.com2
    3. 3. manual3Testing?VSautomatedwhite boxVSblack boxacceptance testintegration testunit test
    4. 4. Unit? 4Unit testing is a method by which individual units ofsource code are tested to determine if they are fit foruse.One can view a unit as the smallest testable partof an application.Unit tests are created by programmers oroccasionally by white box testers during thedevelopment process.
    5. 5. TDD Test Driven Design It’s NOT testing, but using tests to DRIVE thedesign As a side-effect, you got unit tests!With good level of coverage!5
    6. 6. 6REDGREENREFACTORWrite a failing test. With empty class/method.Fill in the class/method implementation. Make the tests pass.Make code better.
    7. 7. Demo: Bank Account Requirements Can create bank accounts Can deposit money into account Can withdraw money from account Throw exception if balance is insufficient Can transfer money from one account to another Can insert and update accounts into database7
    8. 8. 8IDE / Platformhttp://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-webhttps://code.google.com/p/moq/Unit Testing FrameworkMocking Frameworkhttp://nunit.org/Tools
    9. 9. Design 9
    10. 10. 10ARRANGEACTASSERT
    11. 11. Unit11Test
    12. 12. 12
    13. 13. Design 2 13
    14. 14. 14Unit Test
    15. 15. Design 3 15
    16. 16. 16repositoryVSactive record???
    17. 17. 17Unit Test
    18. 18. A good unit test is… Isolated/independent Test one thing at a time. Unit under test doesn’t depend on the other to make test runs. Repeatable Running multiple times yields the same result. Doesn’t rely on environment. Fast You want to repeat it again and again. You want it to be a pleasure to work with. Self-Documenting Test code and code under test clear and concise. Can be a reference for usage of your class/method/etc.18
    19. 19. 19Dependency InjectionSeparation of Interfaceand ImplementationSingle Responsibility Principal
    20. 20. 20Web Controller DI/IoC Setup
    21. 21. 21“Mocking” allow us toisolate dependentunits.
    22. 22. Types of Test Doubles Dummy objects are passed around but never actuallyused. Usually they are just used to fill parameter lists. Fake objects actually have workingimplementations, but usually take some shortcut whichmakes them not suitable for production. Stub objects provide canned answers to calls madeduring the test, usually not responding at all to anythingoutside whats programmed in for the test. Mock objects are pre-programmed with expectationswhich form a specification of the calls they areexpected to receive.22
    23. 23. 23Unit Test
    24. 24. Benefits Instant feedback Write test, write code, see instant result. Promote modularity in your design DI, SRP, Interface vs Implementation. Safety net Change/add code and check if business rules are stillhonored. Free documentation Can be a reference for usage of yourclass/method/etc.24
    25. 25. Done! What is unit testing. TDD. How to write good unit tests. How unit testing can benefit us.25We have learned…Get the codes and slides at…https://github.com/ikhwanhayat/jomweb_unittest
    26. 26. Next? Learning BDD (Behavior Driven Design). Research CI (Continuous Integration). Learn on how to design testable systems. Use unit testing for your project!(I mean, seriously, USE IT!)26You can go on with…
    27. 27. MOAR! Google+ MyDev http://www.mydev.my/automated-testing-dalam-pembangunan-perisian.html ikhwanhayat@gmail.com27THANK YOU FOR LISTENING!
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×