Test fixture

Report a typo

You are provided with a test class SampleClassTests with methods named according to their execution order defined by the test instance lifecycle. This class is intended to test methods of SampleClass which has a complicated instantiation process, so you are also provided with TestUtils helper class with getSampleClassInstance static method that creates instances of SampleClass. However, in order to make TestUtils work, you need run its timeConsumingSetup static method first:

class SampleClass {

    public boolean methodOne() {
        // Implementation details
    }

    public boolean methodTwo() {
        // Implementation details
    }
}

class TestUtils {

    static SampleClass getSampleClassInstance() {
        // implementation details
    }

    static void timeConsumingSetup() {
        // implementation details
    }
}

So your task is to start up TestUtils by calling its timeConsumingSetupmethod, create new instances of SampleClass using the TestUtils.getSampleClassInstance() method (testing each SampleClass method will require a new instance of SampleClass).

Tip: Keep in mind that timeConsumingSetup is really time consuming as its name says.

Sample Input 1:

testMethodOne
testMethodTwo

Sample Output 1:

PASSED
PASSED
Write a program in Java 17
class SampleClassTests {
// Your task is to setup TestUtils and instantiate the instance field.
SampleClass instance;

// @BeforeAll
static void beforeAll() {

}

// @AfterAll
static void afterAll() {

}

// @BeforeEach
void beforeEach() {

}

// @AfterEach
void afterEach() {

}

// @Test
void testMethodOne() {
Assertions.assertTrue(instance.methodOne());
}

// @Test
void testMethodTwo() {
Assertions.assertTrue(instance.methodTwo());
}
}
___

Create a free account to access the full topic