momeunit.framework
Class TestCase

java.lang.Object
  extended by momeunit.framework.Assert
      extended by momeunit.framework.TestCase
All Implemented Interfaces:
Test
Direct Known Subclasses:
TestSuite.ErrorTestCase

public abstract class TestCase
extends Assert
implements Test

An abstract class that every test case should extend. The TestCase has a name property that identifies it. The default value of this property is is name of TestCase subclass without 'packages' prefix (e.g. for class "com.foo.bar.AbcTest" the name of test case will be "AbcTest"). Name of test case can be set of course using setter method setName(String) or constructor TestCase(String). TestCase has methods setUp() and tearDown() for manipulating fixture (instance variables that can be shared by different tests). Developers should override them for setting instance variables and cleaning up after test execution respectively. The code that performs tests and asserts results should be putted in test() method. To run test case and obtain results call run() or run(TestResult) methods. There is a convenience method for creating an empty TestResult instance createResult().

Version:
1.1.2
Author:
Sergio Morozov
See Also:
Test, TestSuite

Constructor Summary
TestCase()
          No-arg constructor.
TestCase(String name)
          Instantiates TestCase and sets name to the name or classname of TestCase implementation without packages part and ".class" suffix of course if name is null.
 
Method Summary
 int countTestCases()
          Returns 1 as the number of test cases that will be run by this test.
protected  TestResult createResult()
          Creates a default TestResult object
 String getName()
          Returns the name of this test case.
 TestResult run()
          A convenience method to run this test, collecting the results with a default TestResult object.
 void run(TestResult result)
          Runs a test and collects its result in a TestResult instance.
 void runBare()
          Runs the bare test sequence.
 void setName(String name)
          Sets name to the name or classname of TestCase implementation without packages part and ".class" suffix of course if name is null.
protected  void setUp()
          Sets up the fixture.
protected  void tearDown()
          Tears down the fixture.
abstract  void test()
          Override to run the test and assert its state.
 String toString()
          Returns a string representation of the test case
 
Methods inherited from class momeunit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestCase

public TestCase()
No-arg constructor. Sets name of test case to classname of TestCase implementation without packages part and ".class" suffix of course.

Since:
1.0

TestCase

public TestCase(String name)
Instantiates TestCase and sets name to the name or classname of TestCase implementation without packages part and ".class" suffix of course if name is null.

Parameters:
name - name of test case or null to set name to classname.
Since:
1.0
Method Detail

setName

public void setName(String name)
Sets name to the name or classname of TestCase implementation without packages part and ".class" suffix of course if name is null.

Parameters:
name - name of test case or null to set name to classname.
Since:
1.0

getName

public String getName()
Returns the name of this test case.

Returns:
name of test case.
Since:
1.0

createResult

protected TestResult createResult()
Creates a default TestResult object

Returns:
Result newly created TestResult instance.
Since:
1.0

countTestCases

public int countTestCases()
Returns 1 as the number of test cases that will be run by this test.

Specified by:
countTestCases in interface Test
Returns:
always 1
Since:
1.0
See Also:
Test.countTestCases()

run

public TestResult run()
A convenience method to run this test, collecting the results with a default TestResult object.

Returns:
populated with results of test TestResult instance.
Since:
1.0

run

public void run(TestResult result)
Description copied from interface: Test
Runs a test and collects its result in a TestResult instance.

Specified by:
run in interface Test

runBare

public void runBare()
             throws Throwable
Runs the bare test sequence.

Throws:
Throwable - if any exception is thrown
Since:
1.0

setUp

protected void setUp()
              throws Exception
Sets up the fixture. This method is called before a test is executed.

Throws:
Exception - if any exception is thrown.
Since:
1.0

test

public abstract void test()
                   throws Throwable
Override to run the test and assert its state.

Throws:
Throwable - if any exception is thrown
Since:
1.0

tearDown

protected void tearDown()
                 throws Exception
Tears down the fixture. This method is called after a test is executed.

Throws:
Exception - if any exception is thrown
Since:
1.0

toString

public String toString()
Returns a string representation of the test case

Overrides:
toString in class Object
Since:
1.0
See Also:
Object.toString()