title: Which is better, ExpectedException or @Test(expected=
body: <p>I have code where I check the exceptions in jUnit. I want to know which of the following is a good jUnit practice?</p>
  
  <p><strong>First</strong></p>
  
  <pre><code>@Rule
  public ExpectedException exception = ExpectedException.none();
  
  @Test
  public void checkNullObject() throws CustomException {
      exception.expect(CustomException.class);
      MyClass myClass= null;
      MyCustomClass.get(null);
  }
  </code></pre>
  
  <p><strong>Second</strong></p>
  
  <pre><code>@Test(expected=CustomException.class)
  public void checkNullObject() throws CustomException {
      MyClass myClass= null;
      MyCustomClass.get(null);    
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Please note that CustomException is a unchecked custom exception. (Though it won't have any impact on this question).</p>