title: JMockit: How to debug tests when using the @Tested annotation?
body: <p>The questions <a href="https://stackoverflow.com/questions/4819257/debug-partial-mock-in-jmockit">Debug Partial Mock in JMockit</a> and <a href="https://stackoverflow.com/questions/28594487/debugging-java-code-tested-with-spock-and-jmockit">Debugging Java code tested with Spock and JMockit</a> already deal with the issue, that breakpoints in your software under test (SUT) get ignored when the class gets redefined/instrumented by JMockit.
  The recommended solution is that you should add an additional breakpoint in your testclass in order to re-activate the breakpoints in SUT, once the execution stops in your testclass.</p>
  
  <p>However, this solution does not work, if you are using the <code>@Tested</code> annotation in your testclass, because in this case the breakpoint in the testclass itself gets ignored.<br>
  Here is an example:</p>
  
  <pre><code>package de.playground;
  
  import static org.hamcrest.Matchers.is;
  import static org.junit.Assert.assertThat;
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import mockit.Expectations;
  import mockit.Injectable;
  import mockit.integration.junit4.JMockit;
  
  @RunWith(JMockit.class)
  public class DebuggingWithJMockitTest {
  
      public interface Collaborator {
          String execute(String... args);
      }
  
      public static class ToTest {
          private Collaborator collaborator;
  
          public ToTest(Collaborator collaborator) {
              this.collaborator = collaborator;
          }
  
          public String doSomething() {
              return collaborator.execute("a", "b");
          }
      }
  
  
      @Injectable
      private Collaborator collaborator;
  
      @Tested
      private ToTest toTest;    
  
      @Test
      public void testHoldOnBreakpoint() {
          new Expectations() {{
                  collaborator.execute((String[]) any); result = "whatever";
              }};
  
          String result = toTest.doSomething(); // add breakpoint here
          assertThat(result, is("whatever"));
      }
  }
  </code></pre>
  
  <p>In this case the debugger does <strong>not</strong> stop in the <code>String result = toTest.doSomething();</code> line. If you do not use the <code>@Tested</code> annotation and initialize the SUT in a <code>@Before</code>method like this:</p>
  
  <pre><code>    // @Tested is not used
      private ToTest toTest;
  
      @Before
      public void before() {
          toTest = new ToTest(collaborator);
      }
  </code></pre>
  
  <p>the breakpoint works perfectly fine.</p>
  
  <p>Is there any workaround how you can debug your code even if you are using the <code>@Tested</code>annotation in the test class?</p>