Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving duplication in Test Driven Development
    primarykey
    data
    text
    <p>I am developing a small parser class TDD style. Here are my tests:</p> <pre><code> ... [TestMethod] public void Can_parse_a_float() { InitializeScanner("float a"); Token expectedToken = new Token("float", "a"); Assert.AreEqual(expectedToken, scanner.NextToken()); } [TestMethod] public void Can_parse_an_int() { InitializeScanner("int a"); Token expectedToken = new Token("int", "a"); Assert.AreEqual(expectedToken, scanner.NextToken()); } [TestMethod] public void Can_parse_multiple_tokens() { InitializeScanner("int a float b"); Token firstExpectedToken = new Token("int", "a"); Token secondExpectedToken = new Token("float", "b"); Assert.AreEqual(firstExpectedToken, scanner.NextToken()); Assert.AreEqual(secondExpectedToken, scanner.NextToken()); } </code></pre> <p>What is bugging me is that the last test is exercising the same lines of code that both <code>Can_parse_a_float()</code> and <code>Can_parse_an_int()</code>. On one hand, it is exercising something that both those methods aren't: that from a source code string, I can get several tokens. On the other hand, were <code>Can_parse_a_float()</code> and <code>Can_parse_an_int()</code> fail, <code>Can_parse_multiple_tokens()</code> would fail too. </p> <p>I feel there are 4 goals at stake here:</p> <ul> <li>I want my tests to show that my <code>Parser</code> parses ints</li> <li>I want my tests to show that my <code>Parser</code> parses floats</li> <li>I want my tests to show that my <code>Parser</code> can parse several ints/floats in a row</li> <li>I want my tests to also serve well as a documentation mechanism (!)</li> </ul> <p>I am offering cookies to anyone who shares his opinions on how to better approach this scenario. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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