title: Is it a bad practice to put JUnit test method into the tested class?
body: <p>Consider a Java class with small library-style static methods.</p>
  
  <p>Is it a bad practice to place JUnit test methods in the same class?</p>
  
  <p>I see the following pros:</p>
  
  <ul>
  <li>JUnit test as a self-documentation is right near the method code</li>
  <li>Will be easy to move this code to another class or package</li>
  </ul>
  
  <p>What are the contras, and why it is a general practice to always separate the test code?</p>
  
  <p>An example:</p>
  
  <pre><code>import org.junit.*;
  
  public class HtmlUtils {
      public static String normalizeBrs(String html) {
          return html.replaceAll("&lt;br\\s*/?&gt;", "&lt;br/&gt;");
      }
  
      @Test
      public void testNormalizeBrs() {
          Assert.assertEquals(normalizeBrs("hello &lt;br /&gt; world &lt;br&gt;"), "hello &lt;br/&gt; world &lt;br/&gt;");
      }
  }
  </code></pre>