0
0
JUnittesting~20 mins

Test classes and naming in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Test Class Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Test Class Naming Conventions

Why is it important to follow naming conventions for test classes in JUnit?

ATo ensure test classes are easily identifiable and grouped logically in reports and IDEs
BTo make test classes run faster during execution
CTo reduce the size of the compiled test code
DTo prevent test classes from being executed accidentally
Attempts:
2 left
💡 Hint

Think about how naming helps humans and tools recognize test code.

Predict Output
intermediate
2:00remaining
JUnit Test Class Naming and Execution

Given the following JUnit test classes, which one will be automatically detected and run by default JUnit 5 test runners?

JUnit
public class CalculatorTest {
    @org.junit.jupiter.api.Test
    void testAdd() {}
}

public class CalculatorTests {
    @org.junit.jupiter.api.Test
    void testSubtract() {}
}

public class TestCalculator {
    @org.junit.jupiter.api.Test
    void testMultiply() {}
}

public class CalcTest {
    @org.junit.jupiter.api.Test
    void testDivide() {}
}
AAll four classes are detected
BOnly CalculatorTest and CalculatorTests are detected
COnly TestCalculator is detected
DOnly CalculatorTest is detected
Attempts:
2 left
💡 Hint

JUnit 5 detects any class with @Test annotations regardless of name by default.

assertion
advanced
2:00remaining
Correct Assertion for Test Class Naming Check

Which assertion correctly verifies that a test class name ends with 'Test' in a JUnit test?

JUnit
String className = "CalculatorTest";
AassertFalse(className.contains("Test"));
BassertEquals(className.startsWith("Test"), true);
CassertEquals(className.length(), 4);
DassertTrue(className.endsWith("Test"));
Attempts:
2 left
💡 Hint

Check the method that tests if a string ends with a specific suffix.

🔧 Debug
advanced
2:00remaining
Debugging a Test Class Naming Issue

Consider this JUnit 5 test class:

public class calculatorTest {
    @org.junit.jupiter.api.Test
    void testAdd() {}
}

Why might this class cause confusion or issues in a team project?

AMissing @Test annotation on the method
BClass name does not follow Java naming conventions (should start with uppercase letter)
CTest method name does not start with 'test'
DClass is missing a package declaration
Attempts:
2 left
💡 Hint

Java class names should follow standard capitalization rules.

framework
expert
2:00remaining
JUnit 5 Test Class Discovery Rules

Which statement correctly describes how JUnit 5 discovers test classes by default?

AJUnit 5 only runs classes whose names end with 'Test' or 'Tests'
BJUnit 5 requires test classes to extend a specific base test class to be discovered
CJUnit 5 runs any class containing at least one method annotated with @Test, regardless of class name
DJUnit 5 only runs classes located in a 'test' package
Attempts:
2 left
💡 Hint

Think about how JUnit 5 improved test discovery compared to older versions.