title: Is there a way to unit test against side effects?
body: <p>Any code can provide side effects. Most of the time, side effects can be a sign of bad design and/or need of refactorisation, but when unit testing I find it hard to test against. Consider the following example:</p>
  
  <pre><code>[Test]
  public void TrimAll_Removes_All_Spaces()
  {
      // Arrange
      var testSubject = "A    string  with     lots   of     space";
      var expectedResult = "Astringwithlotsofspace";
  
      // Act
      var result = testSubject.TrimAll();
  
      // Assert
      Assert.AreEqual(expectedResult, result);
  }
  </code></pre>
  
  <p>that tests the following extension:</p>
  
  <pre><code>public static string TrimAll(this string str)
  {
      PokeAround();
  
      return str.Replace(" ", "");
  }
  </code></pre>
  
  <p>The test will pass, but there is no guard agains side effects. The effects of the call to <code>PokeAround</code> will go completely unnoticed.</p>
  
  <p>Given that you don't know what <code>PokeAround</code> is - it could be anything! - how do you write a test that guards against it? Is it at all possible?</p>
  
  <p><strong>Clarification:</strong>
  There have been a couple of comments about the <code>PokeAround</code> as completely unknown being a very unlikely scenario, since we have the source when we write the test. The reason I asked this question, though, was to find a way to guard against side effects added <em>later on</em>. That is, when I write the test, I might have the exension method look like this:</p>
  
  <pre><code>public static string TrimAll(this string str)
  {
      return str.Replace(" ", "");
  }
  </code></pre>
  
  <p>The test passes, all is good. Then, a month later when I'm on vacation, a colleague add's the <code>PokeAround</code> call. I want the test I already wrote to fail because he did.</p>