<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    BTW, if you're looking the do a JUnit 3 to 4 migration on any other
    code you got lying around, here are the regular expressions I used:<br>
    <br>
    <br>
    // Add @Test<br>
    Replace:<br>
    ^[ \t]+(public +void +test)<br>
    With:<br>
        @Test\n    $1<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    // Remove double @Test's on already @Test annotated files<br>
    Replace:<br>
    ^[ \t]+@Test\n[ \t]+@Test<br>
    With:<br>
        @Test<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    <br>
    // Remove all empty setUp's<br>
    Replace:<br>
    ^[ \*]+((public|protected) +)?void
    +setUp\(\)[^\{]*\{\s*(super\.setUp\(\);)?\s*\}\n([ \t]*\n)?<br>
    With nothing<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    // Add @Before to all setUp's<br>
    Replace:<br>
    ^([ \t]+@Override\n)?[ \t]+((public|protected) +)?(void +setUp\(\))<br>
    With:<br>
        @Before\n    public void setUp()<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    // Remove double @Before's on already @Before annotated files<br>
    Replace:<br>
    ^[ \t]+@Before\n[ \t]+@Before<br>
    With:<br>
        @Before<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    <br>
    // Remove all empty tearDown's<br>
    Replace:<br>
    ^[ \*]+((public|protected) +)?void
    +tearDown\(\)[^\{]*\{\s*(super\.tearDown\(\);)?\s*\}\n([ \t]*\n)?<br>
    With nothing<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    // Add @After to all tearDown's<br>
    Replace:<br>
    ^([ \t]+@Override\n)?[ \t]+((public|protected) +)?(void
    +tearDown\(\))<br>
    With:<br>
        @After\n    public void tearDown()<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    // Remove double @After's on already @After annotated files<br>
    Replace:<br>
    ^[ \t]+@After\n[ \t]+@After<br>
    With:<br>
        @After<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    <br>
    // Remove old imports, add new imports<br>
    Replace:<br>
    ^([ \t]*import[ \t]+junit\.framework\.Assert;\n)?[ \t]*import[
    \t]+junit\.framework\.TestCase;<br>
    With:<br>
    import org.junit.After;\nimport org.junit.Before;\nimport
    org.junit.Test;\nimport static org.junit.Assert.*;<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    <br>
    // Remove all extends TestCase<br>
    Replace:<br>
    [ \t]+extends[ \t]+TestCase[ \t]+\{<br>
    With:<br>
     {<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    File name filter:<br>
    *Test.java<br>
    <br>
    <br>
    <br>
    // Look for import junit.framework;<br>
    Find:<br>
    import junit\.framework<br>
    Manually fix<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    <br>
    <br>
    // Look for ignored tests (FIXME, disabled, ...)<br>
    Find:<br>
    public[ \t]+void[ \t]+\w+test<br>
    Manually fix<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    <br>
    <br>
    // Look for dummy/empty tests<br>
    Find:<br>
    public[ \t]+void[ \t]+test[\w\d]*\(\s*\)\s*\{\s*(//[^\n]*)?\s*\}<br>
    Manually fix<br>
    Regular Expression: on<br>
    Case sensitive: on<br>
    <br>
    <br>
    <br>
    <br>
    Op 26-12-10 20:06, Geoffrey De Smet schreef:
    <blockquote cite="mid:if83n6$guf$1@dough.gmane.org" type="cite">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      Hi guys,<br>
      <br>
      I've updated all testcases on master to use JUnit 4 style<br>
      (except for drools-eclipse and the non-active parts of
      drools-grid).<br>
      The main reason is so we now let hudson report how many testcases
      are ignored (annoted with @Ignore instead of disabled).<br>
      <br>
      Some notes:<br>
      <ul>
        <li><b>Don't disable testcases by prefixing them with FIXME_ or
            disabled_ or by commenting out @Test</b></li>
        <ul>
          <li><b>Instead, add the @Ignore annotation</b></li>
          <ul>
            <li>This way hudson gives us a report on how many testcases
              have been ignored.</li>
          </ul>
        </ul>
        <li><b>Don't use try-catch to test if an exception is thrown.
            Use @Test(expected = MyException.class)</b></li>
        <ul>
          <li>I haven't migrated this in all testcases, as I couldn't
            automate that.</li>
          <li>Please fix it in any code you come across.<br>
          </li>
        </ul>
        <li>To use assertions like assertEquals(a,b), just add this
          import:</li>
        <ul>
          <li>import static org.junit.Assert.*;<br>
          </li>
        </ul>
        <li>Don't import anything from junit.framework.*.</li>
        <ul>
          <li>Import only from org.junit.*</li>
          <li>Configure your Eclipse/Intellij to not propose those
            imports to keep mistakes to a minimum.<br>
          </li>
        </ul>
        <li>TestSuites have been removed.</li>
        <ul>
          <li>Use your Eclipse/IntelliJ to single out tests, packages of
            tests or modules.</li>
          <li>They bring extra maintenance (and seem to be seen as
            legacy since junit 4?)</li>
        </ul>
        <li>Testcases that print out their own name, no longer print out
          their own name</li>
        <ul>
          <li>The junit runner prints out the name already</li>
          <ul>
            <li>Otherwise it looks like it's run twice (while it's not)</li>
          </ul>
        </ul>
      </ul>
      I hope this push (many files were changed) doesn't cause to many
      merge conflicts.<br>
      If it does: just take your revision and upgrade your file to junit
      4 manually.<br>
      <br>
      Learn more:<br>
      - Junit 4 in 60 seconds: <a moz-do-not-send="true"
        class="moz-txt-link-freetext"
        href="http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/">http://www.cavdar.net/2008/07/21/junit-4-in-60-seconds/</a><br>
      <pre class="moz-signature" cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
  </body>
</html>