Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a test case?

I'm having difficulties finding a hard definition of the word "test case". Some sources claim that a test case is a class that extends TestCase. Other sources claim that a test case is a single test method. The JUnit documentation is unclear, it appears to me the words "test case" and "test" mean the same:

The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure. If no exceptions are thrown, the test is assumed to have succeeded.

So what exactly is a "test case", and what is its relationship to a "test"?

like image 233
fredoverflow Avatar asked Nov 05 '22 01:11

fredoverflow


1 Answers

I'd point you over to the JUnit documentation on TestCase. In it, it describes three conditions for what it denotes a TestCase:

  1. implement a subclass of TestCase
  2. define instance variables that store the state of the fixture
  3. initialize the fixture state by overriding setUp()
  4. clean-up after a test by overriding tearDown().

The setUp and tearDown portion I think are critical to understanding here. It's not just simply that a test case is but one annotated method. The test case is that method plus the initialization and destruction of the frame on which a test will be run.

So to answer your question, a test is one annotated method which attempts to verify the workings of a single method while a test case is that test plus the frame in which it will be run.

like image 128
wheaties Avatar answered Nov 10 '22 17:11

wheaties