-1

I have a code base where they define junit test cases as :

public class MyTest extends BaseTestCase
{
    public MyTest( String name )
    {
        super( name );
    }

    public void testSome() throws Exception
    {
        assertTrue (1 == 1);
    }
}

How to do I run this test from eclipse? How do I supply the name in the constructor?

arajek
  • 942
  • 8
  • 12
fastcodejava
  • 39,895
  • 28
  • 133
  • 186

2 Answers2

2

If you are creating the implementation the why not pass the super types construction parameter yourself i.e.

public class MyTest extends BaseTestCase
{
    public MyTest()
    {
        super( "My Test" );
    }

    public void testSome() throws Exception
    {
        assertTrue (1 == 1);
    }
}
GuessBurger
  • 478
  • 4
  • 9
1

You can't run it directly as JUnit runner expect 'Test class should have exactly one public zero-argument constructor' so you have to invoke it manually or as @shim cat have shown or do this per class

protected void setUp() throws Exception {
    System.out.println(" local setUp ");
}
protected void tearDown() throws Exception {
    System.out.println(" local tearDown ");
}

but if you want to share it you can do this per 'TestSuite'

protected void setUp() throws Exception {
    System.out.println(" Global setUp ");
}
protected void tearDown() throws Exception {
    System.out.println(" Global tearDown ");
}
Greg
  • 1,671
  • 2
  • 15
  • 30