Run current Junit test in GWTTestCase

I have a JUnit test that I run on the same class, but recently I wrote an emulated version for GWT. Since the specification is the same, I would like to use the same test case, but I want it to run in the GWT environment, which is usually done by extending the GWTTestCase.

I really want to avoid the pointlessness of copying / pasting, because in the future, tests will probably be added that I should not burden with copying later.

How can I import / inherit my standard unit test to run as a regular test case or GWT test case?

+3
source share
2 answers

I found a solution to this problem.

GWTTestCase, getModuleName null. , GWTTestCase Java- ( ).

, getModuleName, , .

:

public class RegularTest extends GWTTestCase {

  @Override
  public String getModuleName() { return null; }

  public void testIt() {...}

}

... GWT...

public class GwtTest extends RegularTest {

  @Override
  public String getModuleName() { return "some.module"; }

}

, JUnit3, , .

+6

, . junit, gwt junit . , gwt junit test .

public interface IRegularTest {
       public void testSomething();
       public void testSomething2();
}

public class RegularTestImpl implements IRegularTest {

      public void testSomething(){
         // actual test code
      }

      public void testSomething2(){
         // actual test code
      }

}

public class RegularTest extends TestCase implements IRegularTest {
      IRegularTest impl = new RegularTestImpl();

      public void testSomething(){
           impl.testSomething   
      }

      public void testSomething2(){
      }
}


public class GwtTest extends TestCase implements IRegularTest {
      IRegularTest impl = new RegularTestImpl();

      public void testSomething(){
           impl.testSomething   
      }

      public void testSomething2(){
      }
  }
0

Source: https://habr.com/ru/post/1791914/


All Articles