SlideShare a Scribd company logo
• Advanced Object Oriented Design
• Unit Testing Principles
• S.O.L.I.D
• Refactoring
Unit Testing Purpose
 Proof that our classes work properly
 If we repaired the bug in the code, we
would like to be sure it won’t happen again
 Isolate each part of the program and show that
the individual parts are correct.
 Encourages programmers to make
changes to the code since it is easy for
the programmer to check if the piece is
still working properly.
 Unit testing allows the programmer to re-factor code
and make sure the module still works correctly (i.e.
regression testing).
Unit Testing Purpose
 If we did break something, we would like to know about it ASAP
and not wait until QA finds the bug for us
 the sooner a bug is detected, the simpler and less costly it is to fix
 If we break something we would like to know how it
worked originally; unit testing provides a sort of "living
document".
Unit Testing Purpose
 Enforce higher quality code because of SOLID,
CLEAN code and OOP principles that is
necessary for successful unit test creation.
 This results in loosely coupled code, minimized
dependencies in the system, etc.
Unit Testing Purpose
 Unit-testing will not catch every error in the program.
 It will not catch integration errors
 It will not catch performance problems
 It will not catch system-wide issues.
Disadvantages
 Not all code may be covered with Unit
Tests. For example if class has tight
coupled instances
Disadvantages
 Aa a supplement to development, additional time
required for implementation and support of unit
test.
Test Driven Development is not Unit Testing
TDD Disadvantages
 Big time investment, additional complexity,
architecture impact, much more thinking ;)
 Shallow (long) Learning Curve
ReSharper
• Save time on compilation, locating & fixing errors – ReSharper
instantly detects and highlights errors in your code and allows
automatic corrections for most errors – much less possibilities
for bugs
Example:
ReSharper
• Automate routine tasks – Quickly create methods,
properties, variables or classes from their usages, generate
constructors, properties, delegating and equality members;
implement and override members; and much more
Example:
ReSharper
• Get useful hints right when you need them – IntelliSense,
including code completion and quick parameter information
Example:
ReSharper
• Improve your coding practices – Change is easy — with
solution-wide, cross-language refactorings (nearly 6 times as
many as in Microsoft Visual Studio, and growing), additional
automated code transformations, and code cleanup Example:
ReSharper
• Navigate to any corner of your solution – Reach any part of
your code within seconds, with dozens of smart navigation
and search features
Example:
ReSharper
• Handle multi-language solutions with ease – Refactorings,
navigation and search, and coding assistance work across
C#, VB.NET, XAML, ASP.NET, TypeScript, JavaScript, CSS and
more languages – Support all languages in the same
solution – CSLP – TypeScript / HTML / C# / JavaScript
Example:
ReSharper
• ReSharper provides a unit test runner that helps you
run and debug unit tests based on NUnit, xUnit.net,
MSTest, QUnit and Jasmine. You can explore tests,
group them in different ways, break them down into
individual sessions, see test output and navigate to
source code from stack traces.
ReSharper
• Analyzing code coverage with dotCover
• You can easily discover the degree to which the code
of your solution is covered with unit tests.
ReSharper
• For those who are working with Visual Studio Code
have to use TSLint plugin to review, analyze code
• TSLint checks your TypeScript code for readability,
maintainability, and functionality errors.
Example:
Examples of when you should refactor the code before creating unit tests
Tested Method / Class (Unit) has more than one responsibility
Private Class / Methods.
(Possible with using reflection, but will significantly reduce the performance of
tests)
Method / Class don’t allow dependency injection,
for example tightly coupled instances [new
object();]
 All dependencies are explicitly passed in constructor/method parameters or properties. If it is not
passed, it should not be used.
 Must avoid hidden dependencies
 Static methods (like DateTime.Now)
 Singletons
OOD, CLEAN Code and SOLID Principles
OOD principles we must use in order to get testable application
 Encapsulation
• Hide methods / properties…but REMEMBER private objects
shouldn't be tested
 Abstraction
• Domain analysis
• Legacy analysis
• Levels of abstraction
 Inheritance
• Interfaces not concretes
• Code reuse
 Polymorphism
S.O.L.I.D. - Five basic principles of object-oriented
programming and design. The principles, when applied
together, intend to make it more likely that a
programmer will create a system that is easy
to maintain and extend over time. The principles of SOLID
are guidelines that can be applied while working on
software to remove code smells by causing the
programmer to refactor the software's source code until it
is both legible and extensible.
OOD, CLEAN Code and SOLID Principles
 Single responsibility principle - a class should have only a single responsibility
Makes clear the purpose of each class, increases maintainability, and
promotes code reuse
OOD, CLEAN Code and SOLID Principles
 Open / closed principle – should be open for extension, but closed for modification
increases the maintainability and reusability of code
If you will add new functionality, create a new class extending an existing one, rather than changing it
OOD, CLEAN Code and SOLID Principles
 Liskov substitution principle - objects in a program should be replaceable with instances of their
subtypes without altering the correctness of that program - It gives us Code reuse
If you create a new class extending an existing class, make sure it's completely interchangeable with its base
OOD, CLEAN Code and SOLID Principles
 Interface Segregation Principle
OOD, CLEAN Code and SOLID Principles
 Dependency Inversion Principle - Dependency Injection provides a means of injecting
dependencies into an object as opposed to hard coding the dependencies within the object
itself. Classes designed in this matter lend themselves to both unit testing via mocking or
stubbing
OOD, CLEAN Code and SOLID Principles
 Design Patterns
Singleton
Factory
Builder
Object Pool
Command
Mediator
Observer
Strategy
Visitor
Adapter
Decorator
Proxy
StructuralBehavioralCreational
Unit Tests Code coverage
 Unit Tests should cover upper and lower boundary conditions, including exceptions
Unit Tests Code coverage
Unit Tests Code coverage
 Exclude test projects from code coverage statistics
Unit Tests Code coverage
 Why exclude non test projects
Unit Tests
 Creating Unit Tests (without depended objects, no mock objects needed)
Unit Tests
 Introducing Unit Tests with Mock objects
Most of the unit tests requires using of MOCK objects. For example if you have provider to test
and you don’t have connection any time you run the test or you don’t want to be depend on the
connection. In order to create MOCK object we must use interface. We can create stub objects
instead of mock – reduce performance, much more complicated and serves just for state not
behaviour (cant return results)
Unit Tests with Mocks
Depend upon Abstractions. Do not depend upon concretions.
Providing SUT with Mocking, Faking, Stubbing
Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
Fake objects actually have working implementations, but usually take some shortcut which makes them not
suitable for production (an in memory database is a good example).
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside
what's programmed in for the test. Stubs may also record information about calls.
Mocks are what we are talking about here: objects pre-programmed with expectations
which form a specification of the calls they are expected to receive.
Providing SUT with Mocking, Faking, Stubbing
 Creating Mock Object
• The first step – create data on the mocking (properties,
etc.)
• The second step - create expectations on the mock
object. The expectations indicate which methods
should be called on the mocks when the SUT is
exercised.
CODE UNIT TEST
CODE UNIT TEST
CODE UNIT TEST
CODE UNIT TEST
CODE UNIT TEST
Mocking Objects https://github.com/Moq/moq4
Mocking is an integral part of unit testing. Although you can run your unit tests without
use of mocking but it will drastically slow down the executing time of unit tests and also
will be dependent on external resources.
The mock object knows in advance what is supposed to happen during the test (e.g. which
of its methods calls will be invoked, etc.) and the mock object knows how it is supposed to
react (e.g. what return value to provide). The mock will indicate whether what really
happens differs from what is supposed to happen. A custom mock object could be coded
for the expected behavior of each test case (see example)
In some cases we can use FAKE or STUB objects instead of Mock. For example concrete class don’t have an
interface and we can’t mock this object. So we can create FAKE object and use it for testing. In this case we will
dramatically reduce test performance and FAKE object has MUCH more less possibilities for testing.
Mock objects are simulated objects that mimic the behavior of real objects in controlled ways.
VS 2013 Code Coverage Tool
Example

More Related Content

What's hot

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOS
Derek Lee Boire
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
Shaun Abram
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
ikhwanhayat
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
dunglinh111
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
Shaun Abram
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
Cory Foy
 
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAUTest Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
InfinIT - Innovationsnetværket for it
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
Eugenio Lentini
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)Alan Dean
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
Dionatan default
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
Pablo Villar
 

What's hot (20)

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Common Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOSCommon Challenges & Best Practices for TDD on iOS
Common Challenges & Best Practices for TDD on iOS
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAUTest Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
Test Automation and Keyword-driven testing af Brian Nielsen, CISS/AAU
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 

Viewers also liked

Test-driven development & Behavior-driven development basics
Test-driven development & Behavior-driven development basicsTest-driven development & Behavior-driven development basics
Test-driven development & Behavior-driven development basics
Oleksii Prohonnyi
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
Skillwise Group
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
Yu-Chih Lin
 
Unit testing
Unit testingUnit testing
Unit testing
PiXeL16
 
16103271 software-testing-ppt
16103271 software-testing-ppt16103271 software-testing-ppt
16103271 software-testing-ppt
atish90
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
David Berliner
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
Anand Bagmar
 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016
Lemi Orhan Ergin
 

Viewers also liked (12)

Test-driven development & Behavior-driven development basics
Test-driven development & Behavior-driven development basicsTest-driven development & Behavior-driven development basics
Test-driven development & Behavior-driven development basics
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
Unit testing
Unit testingUnit testing
Unit testing
 
16103271 software-testing-ppt
16103271 software-testing-ppt16103271 software-testing-ppt
16103271 software-testing-ppt
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016
 

Similar to Unit Testing Full@

Test driven development
Test driven developmentTest driven development
Test driven development
namkha87
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
Facundo Farias
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
Omar Youssef Shiha
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Testing 101
Testing 101Testing 101
Testing 101
Noam Barkai
 
Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUGlburdz
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
mrjawright
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
AgileNetwork
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
Marcelo Busico
 
Effective unit testing
Effective unit testingEffective unit testing
Effective unit testing
Roberto Casadei
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
Ahmad Kazemi
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
Myeongseok Baek
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
imedo.de
 
Mule testing
Mule testingMule testing
Mule testing
Shanky Gupta
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Sahar Nofal
 

Similar to Unit Testing Full@ (20)

Test driven development
Test driven developmentTest driven development
Test driven development
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
 
Testing 101
Testing 101Testing 101
Testing 101
 
Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Effective unit testing
Effective unit testingEffective unit testing
Effective unit testing
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Mule testing
Mule testingMule testing
Mule testing
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 

Unit Testing Full@

  • 1. • Advanced Object Oriented Design • Unit Testing Principles • S.O.L.I.D • Refactoring
  • 2. Unit Testing Purpose  Proof that our classes work properly  If we repaired the bug in the code, we would like to be sure it won’t happen again  Isolate each part of the program and show that the individual parts are correct.
  • 3.  Encourages programmers to make changes to the code since it is easy for the programmer to check if the piece is still working properly.  Unit testing allows the programmer to re-factor code and make sure the module still works correctly (i.e. regression testing). Unit Testing Purpose
  • 4.  If we did break something, we would like to know about it ASAP and not wait until QA finds the bug for us  the sooner a bug is detected, the simpler and less costly it is to fix  If we break something we would like to know how it worked originally; unit testing provides a sort of "living document". Unit Testing Purpose
  • 5.  Enforce higher quality code because of SOLID, CLEAN code and OOP principles that is necessary for successful unit test creation.  This results in loosely coupled code, minimized dependencies in the system, etc. Unit Testing Purpose
  • 6.  Unit-testing will not catch every error in the program.  It will not catch integration errors  It will not catch performance problems  It will not catch system-wide issues. Disadvantages  Not all code may be covered with Unit Tests. For example if class has tight coupled instances
  • 7. Disadvantages  Aa a supplement to development, additional time required for implementation and support of unit test.
  • 8. Test Driven Development is not Unit Testing
  • 9. TDD Disadvantages  Big time investment, additional complexity, architecture impact, much more thinking ;)  Shallow (long) Learning Curve
  • 10. ReSharper • Save time on compilation, locating & fixing errors – ReSharper instantly detects and highlights errors in your code and allows automatic corrections for most errors – much less possibilities for bugs Example:
  • 11. ReSharper • Automate routine tasks – Quickly create methods, properties, variables or classes from their usages, generate constructors, properties, delegating and equality members; implement and override members; and much more Example:
  • 12. ReSharper • Get useful hints right when you need them – IntelliSense, including code completion and quick parameter information Example:
  • 13. ReSharper • Improve your coding practices – Change is easy — with solution-wide, cross-language refactorings (nearly 6 times as many as in Microsoft Visual Studio, and growing), additional automated code transformations, and code cleanup Example:
  • 14. ReSharper • Navigate to any corner of your solution – Reach any part of your code within seconds, with dozens of smart navigation and search features Example:
  • 15. ReSharper • Handle multi-language solutions with ease – Refactorings, navigation and search, and coding assistance work across C#, VB.NET, XAML, ASP.NET, TypeScript, JavaScript, CSS and more languages – Support all languages in the same solution – CSLP – TypeScript / HTML / C# / JavaScript Example:
  • 16. ReSharper • ReSharper provides a unit test runner that helps you run and debug unit tests based on NUnit, xUnit.net, MSTest, QUnit and Jasmine. You can explore tests, group them in different ways, break them down into individual sessions, see test output and navigate to source code from stack traces.
  • 17. ReSharper • Analyzing code coverage with dotCover • You can easily discover the degree to which the code of your solution is covered with unit tests.
  • 18. ReSharper • For those who are working with Visual Studio Code have to use TSLint plugin to review, analyze code • TSLint checks your TypeScript code for readability, maintainability, and functionality errors. Example:
  • 19. Examples of when you should refactor the code before creating unit tests Tested Method / Class (Unit) has more than one responsibility Private Class / Methods. (Possible with using reflection, but will significantly reduce the performance of tests) Method / Class don’t allow dependency injection, for example tightly coupled instances [new object();]
  • 20.  All dependencies are explicitly passed in constructor/method parameters or properties. If it is not passed, it should not be used.  Must avoid hidden dependencies  Static methods (like DateTime.Now)  Singletons
  • 21. OOD, CLEAN Code and SOLID Principles OOD principles we must use in order to get testable application  Encapsulation • Hide methods / properties…but REMEMBER private objects shouldn't be tested  Abstraction • Domain analysis • Legacy analysis • Levels of abstraction  Inheritance • Interfaces not concretes • Code reuse  Polymorphism
  • 22. S.O.L.I.D. - Five basic principles of object-oriented programming and design. The principles, when applied together, intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time. The principles of SOLID are guidelines that can be applied while working on software to remove code smells by causing the programmer to refactor the software's source code until it is both legible and extensible.
  • 23. OOD, CLEAN Code and SOLID Principles  Single responsibility principle - a class should have only a single responsibility Makes clear the purpose of each class, increases maintainability, and promotes code reuse
  • 24. OOD, CLEAN Code and SOLID Principles  Open / closed principle – should be open for extension, but closed for modification increases the maintainability and reusability of code If you will add new functionality, create a new class extending an existing one, rather than changing it
  • 25. OOD, CLEAN Code and SOLID Principles  Liskov substitution principle - objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program - It gives us Code reuse If you create a new class extending an existing class, make sure it's completely interchangeable with its base
  • 26. OOD, CLEAN Code and SOLID Principles  Interface Segregation Principle
  • 27. OOD, CLEAN Code and SOLID Principles  Dependency Inversion Principle - Dependency Injection provides a means of injecting dependencies into an object as opposed to hard coding the dependencies within the object itself. Classes designed in this matter lend themselves to both unit testing via mocking or stubbing
  • 28. OOD, CLEAN Code and SOLID Principles  Design Patterns Singleton Factory Builder Object Pool Command Mediator Observer Strategy Visitor Adapter Decorator Proxy StructuralBehavioralCreational
  • 29. Unit Tests Code coverage  Unit Tests should cover upper and lower boundary conditions, including exceptions
  • 30. Unit Tests Code coverage
  • 31. Unit Tests Code coverage
  • 32.  Exclude test projects from code coverage statistics Unit Tests Code coverage  Why exclude non test projects
  • 33. Unit Tests  Creating Unit Tests (without depended objects, no mock objects needed)
  • 34. Unit Tests  Introducing Unit Tests with Mock objects
  • 35. Most of the unit tests requires using of MOCK objects. For example if you have provider to test and you don’t have connection any time you run the test or you don’t want to be depend on the connection. In order to create MOCK object we must use interface. We can create stub objects instead of mock – reduce performance, much more complicated and serves just for state not behaviour (cant return results) Unit Tests with Mocks Depend upon Abstractions. Do not depend upon concretions.
  • 36. Providing SUT with Mocking, Faking, Stubbing Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example). Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls. Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
  • 37. Providing SUT with Mocking, Faking, Stubbing  Creating Mock Object • The first step – create data on the mocking (properties, etc.) • The second step - create expectations on the mock object. The expectations indicate which methods should be called on the mocks when the SUT is exercised.
  • 43. Mocking Objects https://github.com/Moq/moq4 Mocking is an integral part of unit testing. Although you can run your unit tests without use of mocking but it will drastically slow down the executing time of unit tests and also will be dependent on external resources. The mock object knows in advance what is supposed to happen during the test (e.g. which of its methods calls will be invoked, etc.) and the mock object knows how it is supposed to react (e.g. what return value to provide). The mock will indicate whether what really happens differs from what is supposed to happen. A custom mock object could be coded for the expected behavior of each test case (see example) In some cases we can use FAKE or STUB objects instead of Mock. For example concrete class don’t have an interface and we can’t mock this object. So we can create FAKE object and use it for testing. In this case we will dramatically reduce test performance and FAKE object has MUCH more less possibilities for testing. Mock objects are simulated objects that mimic the behavior of real objects in controlled ways.
  • 44.
  • 45. VS 2013 Code Coverage Tool
  • 46.