Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I like to draw a distinction between "specs" and "tests."</p> <p>If I am covering a method called <code>GetAverage(IEnumerable&lt;int> numbers)</code>, I am going to write a more or less standard unit test.</p> <p>If I am covering a method called <code>CalculateSalesTax(decimal amount, State state, Municipality municipality)</code>, I am still going to write the unit test, but I'll call it a specification because I'm going to change it up (1) to verify the behaviour of the routine, and (2) because the test itself will document both the routine and its acceptance criteria.</p> <p>Consider:<br/></p> <pre><code>[TestFixture] public class When_told_to_calculate_sales_tax_for_a_given_state_and_municipality() // the name defines the context { // set up mocks and expected behaviour StateSalesTaxWebService stateService = the_dependency&lt;IStateSalesTaxWebService&gt;; MunicipalSurchargesWebService municipalService = the_dependency&lt;IMunicipalSurchargesWebService&gt;; stateService.Stub(x =&gt; x.GetTaxRate(State.Florida)) .Return(0.6); municipalService.Stub(x =&gt; x.GetSurchargeRate(Municipality.OrangeCounty)) .Return(0.05); // run what's being tested decimal result = new SalesTaxCalculator().CalculateSalesTax (10m, State.Florida, Municipality.OrangeCounty); // verify the expected behaviour (these are the specifications) [Test] public void should_check_the_state_sales_tax_rate() { stateService.was_told_to(x =&gt; x.GetTaxRate(State.Florida)); // extension methods wrap assertions } [Test] public void should_check_the_municipal_surcharge_rate() { municipalService.was_told_to(x =&gt; x.GetSurchargeRate(Municipality.OrangeCounty)); } [Test] public void should_return_the_correct_sales_tax_amount() { result.should_be_equal_to(10.65m); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload