Interview Questions

What Is a JUnit Test Fixture?

JUnit Questions and Answers

(Continued from previous question...)

What Is a JUnit Test Fixture?

A test fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Examples of fixtures:

  • Loading a database with a specific, known set of data
  • Copying a specific known set of files
  • Preparation of input data and setup/creation of fake or mock objects

In other word, creating a test fixture is to create a set of objects initialized to certain states.

If a group of tests requires diferent test fixtures, you can write code inside the test method to create its own test fixture.

If a group of tests shares the same fixtures, you should write a separate setup code to create the common test fixture.

(Continued on next question...)

Other Interview Questions