Test Driven Development
Nur Zeynep Taşkın
What is Test Driven Development(TDD)?
 Test-Driven Development (TDD) is a technique for building software that
guides software development by writing tests
 Write test first,then write out logic
 «Code without tests is bad code» Michael C. Feathers
 How can you have a test if there is nothing to test?
Test Driven Development (TDD) Basics
Unit Testing Basics
Production CodeUnit Tests Integration Tests
Effective Unit Tests Are F.I.R.S.T
Fast
to run them
frequently
Independent
of each other
Repeatable
in any
environment
Self-Validating
and so either
passing or failing
Timely
written before the
production code
Advantages Of Unit Testing
Popular Unit Testing Frameworks for .NET
MSTest
Comes with Visual Studio
https://github.com/Micro
soft/testfx
NUnit
Initially ported from JUnit
Current production
release, version 3, has
been completely rewritten
https://github.com/nunit/
nunit
xUnit
Written by the original
invertor of NUnit v2
https://xunit.github.io/
Demo 1
 Requirement:
“Create a library method that takes in a
sentence and a single character as
parameters. The method should return a
number that indicates how many times
the character appears in the sentence.”
What is Mocking?
 Mock Objects
 Fake
 Stub
 Mock
 Popular mocking frameworks for .Net:
 Moq
 Nsubstitute
 NMock3
 Rhino Mocks
 FakeItEasy
 JustMock
Microsoft Fakes
 Fakes come in two flavors:
 Stub
 Shim
Demo 2
TDD and Legacy Code
 Legacy code is
 «Code without tests»
 «Code you're afraid to change»
 TDD is difficult to use on legacy codebases
 The first step is admitting you have a problem
Code Coverage
 If you've been following TDD, then there is no code that was ever written
without being required by a test, so you should always be near 100%
coverage.
 Visual Studio Code Coverage Tool:
Visual Studio Code Coverage
 ExcludeFromCodeCoverage
Other Test Types
 Integration Tests
 User Interface Tests
 Performance and Stress Tests
 Security Tests
 User Acceptance Tests
Test Driven Development

Test Driven Development

  • 1.
  • 2.
    What is TestDriven Development(TDD)?  Test-Driven Development (TDD) is a technique for building software that guides software development by writing tests  Write test first,then write out logic  «Code without tests is bad code» Michael C. Feathers  How can you have a test if there is nothing to test?
  • 3.
  • 4.
    Unit Testing Basics ProductionCodeUnit Tests Integration Tests
  • 5.
    Effective Unit TestsAre F.I.R.S.T Fast to run them frequently Independent of each other Repeatable in any environment Self-Validating and so either passing or failing Timely written before the production code
  • 6.
  • 7.
    Popular Unit TestingFrameworks for .NET MSTest Comes with Visual Studio https://github.com/Micro soft/testfx NUnit Initially ported from JUnit Current production release, version 3, has been completely rewritten https://github.com/nunit/ nunit xUnit Written by the original invertor of NUnit v2 https://xunit.github.io/
  • 8.
    Demo 1  Requirement: “Createa library method that takes in a sentence and a single character as parameters. The method should return a number that indicates how many times the character appears in the sentence.”
  • 9.
    What is Mocking? Mock Objects  Fake  Stub  Mock  Popular mocking frameworks for .Net:  Moq  Nsubstitute  NMock3  Rhino Mocks  FakeItEasy  JustMock
  • 10.
    Microsoft Fakes  Fakescome in two flavors:  Stub  Shim
  • 11.
  • 12.
    TDD and LegacyCode  Legacy code is  «Code without tests»  «Code you're afraid to change»  TDD is difficult to use on legacy codebases  The first step is admitting you have a problem
  • 13.
    Code Coverage  Ifyou've been following TDD, then there is no code that was ever written without being required by a test, so you should always be near 100% coverage.  Visual Studio Code Coverage Tool:
  • 14.
    Visual Studio CodeCoverage  ExcludeFromCodeCoverage
  • 15.
    Other Test Types Integration Tests  User Interface Tests  Performance and Stress Tests  Security Tests  User Acceptance Tests