title: Dependent functional JUnit tests can't share static fields
body: <p>I have the following test (simplified for this question):</p>
  
  <pre class="lang-java prettyprint-override"><code>@FixMethodOrder(MethodSorters.JVM)
  public class ArticleTest {
  
      private static Article article;
  
      @Test
      public void testCreateArticle() {
          articleService.create("My article");
          article = articleService.findByTitle("My article");
          assertNotNull(article);
      }
  
      @Test
      public void testUpdateArticle() {
          article.setTitle("New title");
          articleService.save(article);
          assertNull(articleService.findByTitle("My article"));
          article = articleService.findByTitle("New title");
          assertNotNull(article);
      }
  
  }
  </code></pre>
  
  <p><code>testCreateArticle</code> passes successfully, but <code>testUpdateArticle</code> fails at the first line because <code>article</code> is <code>null</code>, throwing thus an NPE (although the first test asserted that <code>article</code> wasn't <code>null</code>).</p>
  
  <p>Anyone understands why? Note that I run the test with Play Framework (which loves bytecode manipulations), so this may be related somehow...</p>
  
  <p>Also, I know that having dependent tests is a bad practice, but IRL, this isn't a unit test but a kind of <em>test scenario</em>, so I just wanted to give dependent tests a try to understand by myself why people don't like them ;)</p>
  
  <p>But anyway, static fields are supposed to be shared between tests, am I wrong?</p>
  
  <hr>
  
  <p>Update: I know that I could recreate an article in <code>testUpdateArticle()</code>, but the real tests are more complex (maybe I failed at creating an <a href="https://stackoverflow.com/help/mcve">MVCE</a>...). Say I have a third test that depends on the second one (that depends on the first one), etc. The first one needs nothing special, the second one needs a created article, the third one needs a created then updated article, etc. I wanted to try to avoid redoing all DB operations each time, by keeping the state between the tests (making them dependent then).</p>