Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's take a slightly more advanced example: You want to write a method that returns the largest number from a sequence.</p> <p>Firstly, write one or more units test for the method to be tested:</p> <pre><code>int[] testSeq1 = {1, 4, 8, 120, 34, 56, -1, 3, -13}; Assert.That(MaxOf(testSeq1) == 120); </code></pre> <p>And repeat for some more sequences. Also include a null parameter, a sequence with one element and an empty sequence and decide if an empty sequence or null parameter should throw an exception (and ensure that the unit test expects an exception for an empty sequence if that's the case).</p> <p>It is during this process that you need to decide the name of the method and the type of its parameters.</p> <p>At this point, it won't compile.</p> <p>Then write a stub for the method:</p> <pre><code>public int MaxOf(IEnumerable&lt;int&gt; sequence) { return 0; } </code></pre> <p>At this point it compiles, but the unit tests fail.</p> <p>Then implement <code>MaxOf()</code> so that those unit tests now pass.</p> <p>Doing it this way around ensures that you immediately focus on the usability of the method, since the very first thing you try to do is to use it - before even beginning to write it. You might well decide to change the method's declaration slightly at this point, based on the usage pattern.</p> <p>A real world example would apply this approach to using an entire class rather than just one method. For the sake of brevity I have omitted the class from the example above.</p>
    singulars
    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