#1 unit testing
-
Upload
eleksdev -
Category
Technology
-
view
1.304 -
download
0
Transcript of #1 unit testing
![Page 1: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/1.jpg)
AutomationTesting introduction
eleks.com
![Page 2: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/2.jpg)
Agenda
• What and why automated testing?• Types of automated testing• When, Why, What automated
testing is needed• Unit testing 101• Unit testing tools
![Page 3: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/3.jpg)
Why automated testing?• Testing happens to be complex
and expensive• Application tends to be very
complex to completely retest• Frequent releases• Long-term application support• Need to tell if application is
working after each commit/sprint in short term
![Page 4: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/4.jpg)
Types of automated testing
UnitIntegration
Performance
Load
Stress
Penetration
Functional
Many more
![Page 5: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/5.jpg)
When automated testing is needed?
• Good to have it always if possible
• When application requires complex setup scenarios for testing
• When testing takes long time to be performed
![Page 6: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/6.jpg)
When automate?
• During development collaboratively
• After development by separate team if it is even possible
![Page 7: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/7.jpg)
Unit testing
![Page 8: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/8.jpg)
Unit testing
• Smallest testable part• Method level• Isolated• Forces better design• “mock” out what your not
testing fake data access class when testing business logic
![Page 9: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/9.jpg)
Good unit test
• Fast• Readable• Maintainable• Reasonable• Independent• Working
![Page 10: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/10.jpg)
Test Driven Development
![Page 11: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/11.jpg)
Demo
![Page 12: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/12.jpg)
Unit tests naming practices
• MethodName_StateUnderTest_ExpectedBehavior
Add_TwoAndFive_ReturnsSeven• Test[feature being tested]
TestThrowExceptionIfDivideByZero
• Given_PreconditionsWhen_StateUnderTest
Then_ExpectedBehaviorGivenCalculator_When_DivideByZero_Then_ThrowDivideByZeroException
![Page 13: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/13.jpg)
Arrange->Act->Assert
![Page 14: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/14.jpg)
Black magic
![Page 15: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/15.jpg)
Unit testing frameworks
.NET: • xUnit and nUnit (mostly same features)
![Page 16: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/16.jpg)
Isolation techniques
• Dummy – no implementation• Fake/Stub – minimal
implementation• Mock – verify if being called• Spy – record what been called
![Page 17: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/17.jpg)
Demo
![Page 18: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/18.jpg)
Mocking frameworks
Free:• Moq, JustMockLiteCommercial:• TypeMock Isolator,
JustMock, Fakes
![Page 19: #1 unit testing](https://reader036.fdocuments.in/reader036/viewer/2022081604/589ce5f31a28abf86d8b6287/html5/thumbnails/19.jpg)
Inspired by Technology.Driven by Value.
Find us at eleks.com
Have a question? Write to [email protected]