unit testing
Download
Skip this Video
Download Presentation
Unit Testing

Loading in 2 Seconds...

play fullscreen
1 / 7

Unit Testing - PowerPoint PPT Presentation


  • 119 Views
  • Uploaded on

Unit Testing. unit testing is a procedure used to validate that individual units of source code are working properly A unit is the smallest testable part of an application In procedural programming a unit is a function, procedure, subroutine, etc.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Unit Testing' - luann


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
unit testing
Unit Testing
  • unit testing is a procedure used to validate that individual units of source code are working properly
  • A unit is the smallest testable part of an application
    • In procedural programming a unit is a function, procedure, subroutine, etc.
    • In object-oriented programming, a unit is a method
  • The goal is to show that the individual parts are correct
unit testing with xunit
Unit Testing with xUnit
  • Test fixture : a class that contains one or more test methods
  • Test method : a method that executes a specific test
  • Test runner : an application that finds and executes test methods on test fixtures
  • Assertion : a Boolean expression that describes what must be true when some action has been executed
class to be unit tested
Class to be unit tested

public class Account // Class Name

{

private double balance = 0.0; // Member field

public Account(double b) // Constructor

{

balance = b;

}

public double Balance // Getter (Accessor)

{

get { return balance; }

}

public void Withdraw(double amount) // Member Method

{

if (balance >= amount)

balance -= amount;

}

public void Deposit(double amount) // Member Method

{

// TO DO

}

}

test fixture
Test Fixture

[TestClass()]

public class AccountTest

{

...

[TestMethod()]

public void WithdrawTestWithSufficientFunds()

{

Account acct = new Account(100.0);

acct.Withdraw(50.00);

Assert.AreEqual(50.0, acct.Balance);

}

[TestMethod()]

public void WithdrawTestWithInsufficientFunds()

{

Account acct = new Account(100.0);

acct.Withdraw(150.00);

Assert.AreEqual(100.0, acct.Balance);

}

test driven development
Test-Driven Development
  • Never write a single line of code unless you have a failing automated test
  • Refactor to eliminate duplication
red green refactor
Red/Green/Refactor
  • Write the test code
  • Compile the test code(It should fail because you haven’t implemented anything yet.)
  • Implement just enough to compile.
  • Run the test and see it fail.
  • Implement just enough to make the test pass.
  • Run the test and see it pass.
  • Refactor for clarity and to eliminate duplication.
  • Repeat from the top.
ad