0
0
JUnittesting~10 mins

@AfterAll method in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to mark a method that runs once after all tests in a JUnit 5 test class.

JUnit
import org.junit.jupiter.api.[1];

public class CalculatorTest {

    @[1]
    static void cleanup() {
        System.out.println("Cleanup after all tests");
    }
}
Drag options to blanks, or click blank then click option'
ABeforeAll
BAfterEach
CAfterAll
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using @AfterEach instead of @AfterAll
Not making the method static
2fill in blank
medium

Complete the code to ensure the @AfterAll method is static as required by JUnit 5.

JUnit
import org.junit.jupiter.api.AfterAll;

public class DatabaseTest {

    @AfterAll
    [1] closeConnection() {
        System.out.println("Closing DB connection");
    }
}
Drag options to blanks, or click blank then click option'
Astatic void
Bvoid
Cpublic void
Dprivate void
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting static keyword
Making method non-static with @AfterAll
3fill in blank
hard

Fix the error in the @AfterAll method declaration to make it valid in JUnit 5.

JUnit
import org.junit.jupiter.api.AfterAll;

public class ServiceTest {

    @AfterAll
    public [1] cleanup() {
        System.out.println("Service cleanup");
    }
}
Drag options to blanks, or click blank then click option'
Avoid
Bint
CString
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-void return types
Returning values from @AfterAll methods
4fill in blank
hard

Fill both blanks to correctly define an @AfterAll method that prints a message and is static.

JUnit
import org.junit.jupiter.api.AfterAll;

public class NetworkTest {

    @AfterAll
    [1] [2] cleanupNetwork() {
        System.out.println("Network cleanup done");
    }
}
Drag options to blanks, or click blank then click option'
Astatic
Bvoid
Cpublic
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting static keyword
Using non-void return type
5fill in blank
hard

Fill all three blanks to create a valid @AfterAll method with public visibility, static modifier, and void return type.

JUnit
import org.junit.jupiter.api.AfterAll;

public class FileTest {

    @AfterAll
    [1] [2] [3] cleanupFiles() {
        System.out.println("Files cleaned up");
    }
}
Drag options to blanks, or click blank then click option'
Apublic
Bstatic
Cvoid
Dfinal
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or default visibility
Omitting static keyword
Using non-void return type