简体   繁体   中英

JUnit4 Empty Parameterized Test

I've build a xquery Testframework, sometimes I want to test header and inbound and sometimes just Header for example.

I've got therefore 4 Testcases:

headerAndBody, 
headerAndBodyTestsuite,
Header,
HeaderTestsuite

I search the directory for data and construct the tester from it.

And here is the Error:

@Test
    public void someTest() throws Exception{
            if (listHdrInbPayTestSuites.size() > 0) {
                assertTrue(buildTest.testHdrInbPay(testSuiteIdentifier));

            }
        }

The list is EMPTY! but JUnit still says the test ran twice. How can I fix it to say it's an empty test?

Edit:

@Parameter
public String testSuiteIdentifier; (which actually has 2 items)

Edit:(One Testsuite can contain several testcases, so I can't just take another parameter, because I want to identify them by Testsuite name.) 一个Testsuite可以包含多个测试用例,因此我不能仅采用另一个参数,因为我想通过Testsuite名称来标识它们。

Temporary solution: Found a workaround to ignore these tests:

@Before
    public void shouldRunTest() {
        Assume.assumeTrue(listHeaderAndBodyTestSuites.size() > 0);
    }

I'm not really satisfied with this solution since the information "test skipped" can be misleading.

Any other approaches/ideas?

JUnit does not support the concept of an empty test. An ignored test is the concept that comes closest to it.

In order to not increase the test count you have to ensure that the data values are not part of the parameters. This means you have to remove them within your @Parameters method. Here is an example that removes some data values for the Fibonacci test example of the Parameterized runner's documentation.

@Parameters
public static Iterable<Object[]> data() {
    Collection<Object[]> currentData = Arrays.asList(
        new Object[][] {
            { 0, 0 },
            { 1, 1 },
            { 2, 1 },
            { 3, 2 },
            { 4, 3 },
            { 5, 5 },
            { 6, 8 }
        }
    );
    return currentData.stream()
        .filter( dataSet -> dataSet[1] > 3 )
        .collect( Collectors.toList() );
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM