• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Real Life Unit Testing
 

Real Life Unit Testing

on

  • 4,310 views

Tools are not enough. If you want to succeed overtime, you need more ammunition. Some people call them best practices. We call them real life lessons.Why should every developer unit test his code, ...

Tools are not enough. If you want to succeed overtime, you need more ammunition. Some people call them best practices. We call them real life lessons.Why should every developer unit test his code, Unit testing tools,TDD & Unit testing best practices, How to avoid writing fragile tests and Testing special scenarios

Statistics

Views

Total Views
4,310
Views on SlideShare
4,295
Embed Views
15

Actions

Likes
3
Downloads
0
Comments
3

3 Embeds 15

http://www.slideshare.net 10
http://www.linkedin.com 4
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

13 of 3 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Software project should not be a ticking bomb.
  • AtomicRepeatableNo dependency between tests/test orderClear pass/fail criteria
  • The backbone of TDD (and development)Show how CI & script runner run the test suite – perhaps publish results to web

Real Life Unit Testing Real Life Unit Testing Presentation Transcript

  • Real life unit testing
    Dror Helper
  • Who am I?
    Software Developer
    Part time blogger http://blog.drorhelper.com/@dhelper
    One thing was the same wherever I worked…
  • Agenda
    Unit tests - what, how and why
    Tools of the trade
    How to write better tests
    Writing tests when it’s hard to test
  • Sounds familiar?
    Every ten bugs I fix I create a new one…
    I have no idea what caused that issue…
    I’d rather not change that function…
    It is impossible to unit test our project!
    Setting my test environment takes too long
  • Avoid stupid bugs
  • Unit tests
    Unit Tests
    Test specific functionality
    Clear pass/fail criteria
    Good unit test runs in isolation
  • What is a Unit Test
    Unit tests
    [TestMethod]
    public void CheckPassword_ValidUser_ReturnTrue()
    {
    bool result = CheckPassword(“user”, “pass”);
    Assert.IsTrue(result);
    }
  • What is a Unit Test
    Unit tests
    [Test]
    public void CheckPassword_ValidUser_ReturnTrue()
    {
    bool result = CheckPassword(“user”, “pass”);
    Assert.That(result, Is.True);
    }
  • The kind of test
    Unit tests should be:
    Small
    Atomic
    Test a single functional unit
    Isolated!
    Integration tests are used to test system wide functionality
    Unit tests
  • Why use automated unit tests?
    Quick feedback
    Regression
    Gain control of your code
    Unit tests
  • Avoid stupid bugs
    Unit tests
  • Tools of the trade
    Tools
    Server
    Source Control
    Build Server
    Build Script
    Dev Machine
    Test Runner
    Unit Testing Framework
    Isolation Framework
    Code Coverage
  • Continuous Integration
    Tools
    What’s new?
    Commit
    Build Server
    (TeamCity)
    There you go
    Start working
    Build artifacts
    We automatically got
    • Error reports & logs
    • New version installer
    • Help files
    • More…
    Source Control
    (SVN)
    Build Agents
    (FinalBuilder)
  • Build Script at a Glance
    Tools
  • TeamCity at a Glance
    Tools
  • Development environment
    Make it easy to write and run tests
    Unit test framework
    Test Runner
    Isolation framework
    Know where you stand
    Code coverage
    Tools
  • Unit testing frameworks
    NUnit
    xUnit
    MSTest
    Gallio (MbUnit)
    NBehave
    List of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
    Tools
  • Test Runners
    Tools
    • Visual Studio (MSTest)
    • TestDrive.Net
    • R# TestRunner
    • CodeRushTestRunner
    • NUnitIt
  • How to write better tests
    Write better tests
    Write easy to understand tests
    Reuse code where appropriate
    Running test should be easy
    Avoid fragile tests
    Trust Your Tests!
  • Readability is important
    Why did the test fail?
    Avoid unnecessary debugging
    Understand what the test does!
    Write better tests
  • Easy to understand unit tests
    Names are important
    Don’t be afraid to repeat yourself
    Arrange-Act-Assert
    Or Act-Assert-Arrange
    Write better tests
  • Write readable tests
    Test only one thing (most of the time)
    KISS – avoid logic in your test
    Write better tests
  • Duplicate code problem
    Write better tests
    After refactoring I need to re-write my tests.
    Writing the same code twice is wrong
  • Reuse code
    Create objects using factories
    Manipulate and configure initial state
    Run common tests in common methods
    Write better tests
  • Just remember
    Readability is important
    - It’s still ok to repeat yourself
    Write better tests
  • Easy to run
    Running the tests takes too long
    Setting complicated testing environment
    Write better tests
  • Test should be easy to run
    Integration vs. Unit tests
    Simple configuration
    Use fakes
    Write better tests
  • Fragile tests
    Tests fail every time I change my code
    Write better tests
  • Avoid over specification
    Write better tests
    Don’t test private/internal (most of the time)
    Fake as little as necessary
    Test only one thing (most of the time)
  • Testing the un-testable
    First - better understand the problem
    Isolation framework
    Design/refactor for Testability
    Reflection
    Use integration tests
    Testing un-testable
  • Unit tests = avoid stupid bugs
  • Resources
    This Week In Test webcast www.typemock.com/this-week-in-test/
    Book: The art of unit testing
    Typemock insider’s blog: blog.typemock.com
    Follow us on twitter @typemock