Developer Testing Tricks

Slides:



Advertisements
Similar presentations
Object Oriented Analysis And Design-IT0207 iiI Semester
Advertisements

SPL/2010 Test-Driven Development (TDD) 1. SPL/
Test-First Programming. The tests should drive you to write the code, the reason you write code is to get a test to succeed, and you should only write.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Local Touch – Global Reach The New Tester Matthew Eakin, Manager Managed Testing Practice Sogeti, USA.
Evaluating Requirements. Outline Brief Review Stakeholder Review Requirements Analysis Summary Activity 1.
Information System Engineering
CS351 © 2003 Ray S. Babcock Software Testing What is it?
Evaluating Requirements
Extreme Programming Team Members Gowri Devi Yalamanchi Sandhya Ravi.
Evaluating Requirements
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
By for Test Driven Development: Industry practice and teaching tool Robert Vanderwall, Ph.D. 1 WISTPC-15.
Testing. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
Chapter 3 – Agile Software Development 1Chapter 3 Agile software development.
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
Understand Application Lifecycle Management
University of Palestine software engineering department Testing of Software Systems Testing throughout the software life cycle instructor: Tasneem Darwish.
Software testing Main issues: There are a great many testing techniques Often, only the final code is tested.
Software Construction Lecture 18 Software Testing.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
TEST-1 6. Testing & Refactoring. TEST-2 How we create classes? We think about what a class must do We focus on its implementation We write fields We write.
Chapter 2 Software processes. Topics covered Software process models Process activities Coping with change.
Test-Driven Development Eduard Miric ă. The problem.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
1 Presentation Title Test-driven development (TDD) Overview David Wu.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Evaluating Requirements
UML - Development Process 1 Software Development Process Using UML.
Dynamic Testing.
Automated Testing in Sakai Testing applications and services in isolation and in context Josh Holtzman, UC Berkeley David Haines, University of Michigan.
Project Management Software development models & methodologies
TDD Unit tests from a slightly different point of view Katie Dwyer.
Chapter 3 Agile software development 1 Chapter 3 – Agile Software Development.
Principles of Programming & Software Engineering
Software Development.
Software Testing.
Unit Testing - solid fundamentals
Test-driven development
Recall The Team Skills Analyzing the Problem (with 5 steps)
Software Testing.
Testing All Input is Evil pt 2.
Chapter 18 Maintaining Information Systems
Putting Testing First CS 4501 / 6501 Software Testing
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Paul Ammann & Jeff Offutt
Software Testing.
Principles of Programming and Software Engineering
Chapter 13 & 14 Software Testing Strategies and Techniques
Dilbert Scott Adams Manage It! Your Guide to Modern, Pragmatic Project Management. Johanna Rothman.
Advantages OF BDD Testing
Johanna Rothman Create Technical Excellence Chapter 9
What do you need to know about XP?
Paul Ammann The Agile Heresy: What Drives Traditional Software Engineering, and Why Agile Turns it Upside Down Paul Ammann.
Paul Ammann & Jeff Offutt
The Object-Oriented Thought Process Chapter 05
Model Based Testing Venkata Ramana Bandari, Expert Software Engineer
Testing and Test-Driven Development CSC 4700 Software Engineering
Chapter 3 – Agile Software Development
CSE 303 Concepts and Tools for Software Development
Baisc Of Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Testing.
Extreme Programming.
A Few Review Questions Dan Fleck Spring 2009.
Test Cases, Test Suites and Test Case management systems
Refactoring Low Level/High Level.
Testing.
Accessible Forms Gaby de Jongh, IT Accessibility Specialist
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Developer Testing Tricks Brian Takita, Pivotal Labs

Abstract This presentation will go over a number of testing technologies and methodologies that will increase the odds of success for Rails projects. The goals of the talk is to, present a set of testing related situations and experience in solving a number of issues, raise the audiences' awareness over effective ways of communicating through tests, and emphasize skills and courage to solve testing issues.

Reasons to Test Executable specifications TDD – Make your design better Verification - Keep your code safe Support experimentation and refactoring Empirical software development

Focus of Tests Method Manual Automated Audience Customer Developer Scope Unit Functional Integration

Granularity of Tests Happy Path Testing Edge Case Testing

Happy Path Testing Tests the piece of functionality in a "normal" situation Quick and dirty way to see if your functionality is working Useful in integration and functional tests

Happy Path Selenium Example describe "A User on the home page" do before do open "/" end describe "clicking the up vote" do describe "when logged in" do @user = users(:quentin) element(“link=Login”).click element("name=login").type(@user.login) element("name=password").type('test') element("name=commit").click it "increments the vote count by 1" do element("css=.score").assert_contains('0') element("css=.up").click element("css=.score").assert_contains('1')

Edge Case Testing Tests the edge cases of the piece of functionality Invalid Data Invalid fixture state Ensures full code coverage Useful in Unit tests

Edge Case Testing VoteSubmissions::UpVoteSubmissionsController POST create when not logged in redirects to SessionsController#new when logged in and passed invalid data does not create a Vote responds with an error and passed valid data and the User does not have a Vote for the PainPoint creates a Vote responds with json representation of the User data of the PainPoint and the User has a Vote for the PainPoint does not create a new Vote sends an up_vote event to the existing Vote

Lifecycle of a Test TDD Tests to drive the design of the software Regression Testing Tests to ensure that your software still works when you make changes Retirement of a Test Tests that are no longer useful

TDD Red -> Green -> Refactor Write the tests first, then implement the software These tests drive design Tests should be refactored You can manually test drive your code, its just slower and you dont get to keep the tests

Goals of TDD Specification, not validation Feedback Developer makes smaller steps Developer knows when the code is finished Developer has an example of using the implementation code Developer maintains focus on the objective Fast Iterations Developer rhythm Confidence Simplicity YAGNI (You Aint Gonna Need It) Make a regression test

TDD – Test your tests Red -> Green -> Refactor Its easy to make a test that does not test anything For example, testing the elements within an empty collection Use Preconditions to set the context of your test

Retroactive TDD Comment out the implementation you want to test Write the tests Watch them fail for expected reasons Uncomment the implementation Watch the tests pass Refactor

Regression Test After the TDD phase, your tests serve to make sure your software still works Tests live longer than the code (the implementation often changes)

Regression Test Goals Verify your software does not break due to changes in implementation or state Courage Support Experimentation & Refactoring Documentation Clarity Fail in the right places Avoid crying wolf due to unnecessary brittleness Keep tests predictable

Regression Test - Documentation Tests should clearly document your system Refactor the test if it is not clear or focused Nested ExampleGroups are very helpful in showing contextual logic Unit tests should match the logical layout of your software

Regression Test – Clarity and Focus User sends messages to friends and receives replies from them ↲ when the friend responds back otherwise no reply is sent User #send_message sends a Message to a friend #receive_message receives a Message from a friend

Monitoring your tests Are you getting good coverage? Are these tests still relevant? How often do these tests fail? How long does your suite take to run? Are your tests easy to run or do they get in the way?

TDD & Regression Testing Their goals are not necessarily aligned Things change What is relevant today is not tomorrow Refactor early and often

Retirement of a Test If the test no longer contributes to logical coverage in its particular scope (unit, functional, integration, etc), then retire it.

Obsolete Tests They add clutter and make your test suite harder to read and reason about They take time to run They take space

Testing Untested Software Working Effectively with Legacy Code - Michael Feathers Seams Places where you can alter behavior without editing the code Dont forget to Retroactively TDD test your tests Rails MVC separation makes it easier to add tests later

Consequences of Refactoring Extract class or module refactoring can be supported by existing tests You may or may not need to test drive the extracted module It depends on your situation If you are unsure, error on the side of writing tests

Why Test Drive your refactorings You can get defect localization The tests help the design of your extracted module

Why Not Test Drive your refactorings TDD may disrupt your "refactoring flow" You may want your refactoring to be a spike to quickly experiment on an idea You can always retroactively TDD your changes You already have test coverage

When finished with the refactoring Refactor your tests Move the tests into the correct places Use abstraction in your tests by verifying that the dependencies are utilized

Test Fixture Fixed state to be used as a baseline for your tests Mock & Stubs Instantiated Fixtures Transactional Fixtures Fixture Scenario Object Mother

Test Drive Fixtures Verify your fixtures are in a valid state Test drive a change to your DB schema by making a fixture test Verifies that your fixtures reflect reality Keeps your fixtures maintainable Discourages your fixture set from getting large describe "users.yml" do attr_reader :user describe "bob" do before do @user = users(:bob) end specify "was in the green and red room" do user.rooms.should include(rooms(:green)) user.rooms.should include(rooms(:red))

Fixture Scenarios http://code.google.com/p/fixture- scenarios/ describe User do describe “enter” do describe “when all of the rooms are full” do scenario :all_rooms_are_full it “raises a NoRoomAvailableError” do user = users(:bob) lambda {user.enter}.should raise_error(NoRoomAvailableError) end

One off cases You do not necessarily need to make a new fixture