Junit4: 4.9 final์—์„œ Categories + Parameterized๊ฐ€ ์—ฌ์ „ํžˆ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค (# 74 ๋‹ค์‹œ ์—ด๋ฆผ?).

์— ๋งŒ๋“  2011๋…„ 08์›” 24์ผ  ยท  8์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: junit-team/junit4

์นดํ…Œ๊ณ ๋ฆฌ + ๋งค๊ฐœ ๋ณ€์ˆ˜ํ™” ๋œ ๋“€์˜ค๋Š” ์—ฌ์ „ํžˆ ์ƒˆ๋กœ์šด junit 4.9 ์ตœ์ข… ๋ฒ„์ „์—์„œ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š์ง€๋งŒ # 74 ๋ณ€๊ฒฝ ํ›„ ํ”ผ๋“œ๋ฐฑ์ด ๋ฉ”์‹œ์ง€์—†๋Š” NPE๋ณด๋‹ค ํ›จ์”ฌ ๋‚ซ์Šต๋‹ˆ๋‹ค. ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค์—๋Š” ํด๋ž˜์Šค ์ˆ˜์ค€์˜ @Category ์ฃผ์„์ด ์žˆ์Šต๋‹ˆ๋‹ค.
์Šคํƒ ํŠธ๋ ˆ์ด์Šค :

java.lang.Exception: Category annotations on Parameterized classes are not supported on individual methods.
    at org.junit.runners.model.InitializationError.<init>(InitializationError.java:30)
    at org.junit.experimental.categories.Categories.assertNoDescendantsHaveCategoryAnnotations(Categories.java:179)
    at org.junit.experimental.categories.Categories.assertNoCategorizedDescendentsOfUncategorizeableParents(Categories.java:171)
    at org.junit.experimental.categories.Categories.assertNoCategorizedDescendentsOfUncategorizeableParents(Categories.java:173)
    at org.junit.experimental.categories.Categories.<init>(Categories.java:156)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:35)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

์ฝ”๋“œ ์Šค ๋‹ˆํŽซ-๊ฐ„๊ฒฐํ•จ์„ ์œ„ํ•ด ์ƒ๋žต ๋œ ๊ฐ€์ ธ ์˜ค๊ธฐ, ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์™„์ „ํ•œ ์ผ์‹ / ๊ฐœ๋ฏธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ œ๊ณต ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ฌธ์ œ๊ฐ€์žˆ๋Š” ํ…Œ์ŠคํŠธ :

@RunWith(Parameterized.class)
@Category(SampleCategory.class)
public class AdditionTest {

    static final Integer[][] SCENARIOS = new Integer[][] { { 2, 2, 4 },
            { -2, 2, 0 }, { -4, -1, -5 }, };
    int one, two, expectedSum;

    public AdditionTest(int one, int two, int expectedSum) {
        super();
        this.one = one;
        this.two = two;
        this.expectedSum = expectedSum;
    }

    <strong i="12">@Test</strong>
    public void addAndSeeWhatHappens() throws Exception {
        assertEquals("sum", expectedSum, one + two);
    }

    <strong i="13">@Parameters</strong>
    public static Collection<Integer[]> regExValues() {
        return Arrays.asList(SCENARIOS);
    }

}

์Šค์œ„ํŠธ :

@RunWith(Categories.class)
@IncludeCategory(SampleCategory.class)
@SuiteClasses({ AdditionTest.class, MultiplicationTest.class })
public class SampleSuite {

}

AdditionTest์—์„œ @Category ๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌํ•˜๋ฉด Suite๊ฐ€ MultiplicationTest๋ฅผ ์ž˜ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค ( "์ผ๋ฐ˜"ํ…Œ์ŠคํŠธ ๋ฉ”์„œ๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๊ณ  ํด๋ž˜์Šค ์ˆ˜์ค€ @Category๋„ ์žˆ์Œ).

bug parameterized regression

๋ชจ๋“  8 ๋Œ“๊ธ€

ํŒŒ๋ฒจ,

๋ฒ„๊ทธ ์‹ ๊ณ ์— ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ฒจ๋ถ€ ๋œ ์ปค๋ฐ‹์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์•ž์œผ๋กœ 24 ์‹œ๊ฐ„ ๋‚ด์— ๊ฐ„๋‹จํžˆ ์‚ดํŽด๋ณผ ์‹œ๊ฐ„์ด ์žˆ์Šต๋‹ˆ๊นŒ? ๊ฐ์‚ฌ.

์˜ˆ, ์‹œ๋„ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ช‡ ์‹œ๊ฐ„ ํ›„์— ๋Œ์•„์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด์ œ ์™„๋ฒฝํ•˜๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
categorized_parameters_fix์—์„œ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค๊ณ  junit4.10-SNAPSHOT์„ ๊ตฌ์ถ•ํ–ˆ์œผ๋ฉฐ ์ด์ œ Parameterized์™€ Category๊ฐ€ ํ–‰๋ณตํ•˜๊ฒŒ ํ•จ๊ป˜ ์‚ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ชจ์Œ์— ์ถ”๊ฐ€ ๋œ ์ด๋ก ์— ๋Œ€ํ•ด์„œ๋„ ๋™์ผํ•œ ์‚ฌ์‹ค์ด ์‚ฌ์‹ค์ž„์„ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

@RunWith(Theories.class)
@Category(SampleCategory.class)
public class NumberTheoryOrSomething {

    <strong i="7">@DataPoints</strong>
    public static int[] someNumbers = { 1, 4, -5, 10, -100, -3, 0, 45, -997 };

    <strong i="8">@Theory</strong>
    public void positiveTheory(int one, int two) {
        assumeTrue(one >= 0 && two >= 0);
        assertTrue("The result should not be negative", one * two >= 0);
    }

    <strong i="9">@Theory</strong>
    public void surprisinglyPositiveTheory(int one, int two) {
        assumeTrue(one < 0 && two < 0);
        assertTrue("The result should be positive", one * two >= 0);
    }
}

์ˆ˜์ •์œผ๋กœ ์ธํ•ด 4.9.1์ด ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์Šต๋‹ˆ๊นŒ?

์‚ฌ์‹ค, ์ €๋Š” 4.9.1์„ ๊ฑด๋„ˆ ๋›ฐ๊ณ  ์žˆ์œผ๋ฉฐ,์ด ์ˆ˜์ • ์‚ฌํ•ญ์„ ํฌํ•จํ•˜์—ฌ ๋‹ค์Œ ์ฃผ์ฏค์— 4.10์„ ์ถœ์‹œ ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์—ฌ์ „ํžˆ ๋‚˜๋ฅผ ์œ„ํ•ด ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. junit 4.12๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

@ 1hanymhajna ์ตœ์†Œํ•œ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

ํ™•์‹คํ•œ:
@RunWith (Parameterized.class)
public class myClass {

 @Parameterized.Parameters(name = "{index}: params for test:({0})")
public static ArrayList<String[]> loadProcessorList() throws IOException {
    return MyParams.loadParams();
}

@Category (myCategory.class)
@ํ…Œ์ŠคํŠธ
public void myTest () {
Assert.assertTrue (true);
}

}

์นดํ…Œ๊ณ ๋ฆฌ์—†์ด์ด ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์ž˜ ์ž‘๋™ํ•˜์ง€๋งŒ ๋งค๊ฐœ ๋ณ€์ˆ˜ํ™” ๋œ ํด๋ž˜์Šค๊ฐ€์žˆ๋Š” ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ๋„ฃ์œผ๋ฉด ๋‹ค์Œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋งค๊ฐœ ๋ณ€์ˆ˜ํ™” ๋œ ํด๋ž˜์Šค์˜ ์นดํ…Œ๊ณ ๋ฆฌ ์ฃผ์„์€ ๊ฐœ๋ณ„ ๋ฉ”์„œ๋“œ์—์„œ ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

@ 1hanymhajna ๋น ๋ฅธ ์‘๋‹ต์— ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์šฐ๋ฆฌ๋Š” ์ด๊ฒƒ์„ ๊ณ ์น  ์ˆ˜๋„ ์žˆ์ง€๋งŒ JUnit5์—์„œ๋Š” ํŠน๋ณ„ํ•œ ์‹คํ–‰๊ธฐ์—†์ด ๋งค๊ฐœ ๋ณ€์ˆ˜ํ™” ๋œ ํ…Œ์ŠคํŠธ๋ฅผ ์ง€์›ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. JUnit5๊ฐ€ ์นดํ…Œ๊ณ ๋ฆฌ + ๋งค๊ฐœ ๋ณ€์ˆ˜๋ฅผ ์ง€์›ํ•˜๋„๋ก ๋ฒ„๊ทธ๋ฅผ ์ œ์ถœํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰