JUnit, Java’da yazılan bir unit test framework’üdür. İç içe testler, bir test case’inde başka bir test case’inin çalışmasına gerek duyulan durumları ifade eder. JUnit’te bu tür durumlar, @Nested annotasyonu kullanarak tanımlanabilir.
Aşağıdaki örnekte, iki farklı test case’i içeren bir test class’ı gösterilmiştir:
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; public class NestedTestCases { @Test void testCase1() { // test logic } @Nested class InnerTestCases { @Test void testCase2() { // inner test logic } @Test void testCase3() { // another inner test logic } } }
Bu örnekte, testCase1 ve InnerTestCases adlı iki test case’i bulunmaktadır. İç test case’leri, @Nested annotasyonu kullanarak tanımlanmış bir inner class olarak yazabilirsiniz. İç test case’leri tek tek çalıştırmak için JUnit tarafından desteklenmektedir.