0
0
JUnittesting~10 mins

Package-level test organization 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 declare a test class in the correct package.

JUnit
package com.example.tests;

import org.junit.jupiter.api.Test;

public class [1] {
    @Test
    void sampleTest() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
ATestSample
BExampleTest
CSampleTest
DTestClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid class names that don't follow Java naming conventions.
Omitting the package declaration.
2fill in blank
medium

Complete the code to import the JUnit 5 test annotation.

JUnit
package com.example.tests;

import [1];

public class SampleTest {
    @Test
    void sampleTest() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
Aorg.junit.Before
Borg.junit.Test
Corg.junit.jupiter.api.BeforeEach
Dorg.junit.jupiter.api.Test
Attempts:
3 left
💡 Hint
Common Mistakes
Importing JUnit 4 annotations instead of JUnit 5.
Using incorrect package names.
3fill in blank
hard

Fix the error in the package declaration to organize tests properly.

JUnit
package [1];

import org.junit.jupiter.api.Test;

public class SampleTest {
    @Test
    void sampleTest() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
Acom.example.tests
Bcom.example.testing
Ccom.example.test
Dcom.example.testcases
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'test' instead of plural 'tests'.
Using unrelated package names that don't reflect test purpose.
4fill in blank
hard

Fill both blanks to create a package-info.java file with a test package description and annotation.

JUnit
import org.junit.platform.suite.api.SelectPackages;
/**
 * [1]
 */
@[2]("com.example.tests")
package com.example.tests;
Drag options to blanks, or click blank then click option'
AThis package contains unit tests
BThis package contains integration tests
CSelectPackages
DSelectClasses
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect annotation names.
Writing unrelated package descriptions.
5fill in blank
hard

Fill all three blanks to define a test suite that runs all tests in the package.

JUnit
import org.junit.platform.suite.api.Suite;
import org.junit.platform.suite.api.[1];

@Suite
@[2]("com.example.tests")
public class [3] {
}
Drag options to blanks, or click blank then click option'
ASelectPackages
BSelectClasses
CAllTestsSuite
DTestSuite
Attempts:
3 left
💡 Hint
Common Mistakes
Using @SelectClasses instead of @SelectPackages for package-level suites.
Choosing unclear or inconsistent class names.