Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit test using NUnit in Visual Studio

Unit test using NUnit in Visual Studio

nunit, unittest, visualstudio

Avatar for Luca Bonini

Luca Bonini

June 22, 2018
Tweet

More Decks by Luca Bonini

Other Decks in Technology

Transcript

  1. 3 THEY DIDN’T USE TDD Le cinture di sicurezza sono

    un dispositivo di sicurezza. In caso di incidente, uno dei più importanti meccanismi di protezione per chi si trova all'interno dell'autovettura.
  2. 5 Unit test definition A unit test is the smallest

    testable part of an application like functions, classes, procedures, interfaces. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
  3. 6 A good unit test • Able to be fully

    automated • Has full control over all the pieces running (Use mocks or stubs to achieve this isolation when needed) • Can be run in any order if part of many other tests • Runs in memory (no DB or File access, for example) • Consistently returns the same result (You always run the same test, so no random numbers, for example) • Runs fast • Tests a single logical concept in the system • Readable • Maintainable • Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
  4. 7 Unit test naming practices • MethodName_StateUnderTest_ExpectedBehavior Add_TwoAndFive_ReturnsSeven • Test[feature

    being tested] TestThrowExceptionIfDivideByZero • Given_Preconditions When_StateUnderTest Then_ExpectedBehavior GivenCalculator_When_DivideByZero_Then_ThrowDivideByZeroException
  5. 13 Nunit (most important) Attributes • Test Fixture • Setup

    • Teardown • Test Fixture Setup • Test Fixture Teardown • Expected Exception • Category • Ignore
  6. 14