简体   繁体   中英

A Parameterized Parameterized test or Parameterized Suite with a before and after

I have an @Parameterized JUnit test which all works. Now I'm trying to create a new test that runs that same @Parameterized test once for 20 database configurations.

Been having a look online and there are various people who have asked for this but there doesn't seem to be a satisfactory solution. I had a look at Suite but it can't run Parameterized test and it doesn't have any annotations that can be run in between the suite tests to prepare for the next suite test.

Standard Parameterized class:

@RunWith(Parameterized.class)
public class MyParameterizedTest {
    // works as normal
}

Here is some pseudo code of what I am looking for:

@RunWith(RunParameterizedLots.class)
@ParameterizedClassToTest(MyParameterizedTest.class)
public class RunParameterizedLotsOfTimes<T> {

    @ListOfTestStuff
    public List<T> getList() {
        return list of T;
    }

    @BeforeRunningMyParameterizedTest
    public void beforePtest(T i) {
       setupDatabaseConfig(i);
    }

    @AfterRunningMyParameterizedTest
    public void afterPtest() {
        teardownDatabaseConfig(i);
    }

}

None of this is written I have spent 2 days reading JUnit documentation and don't seem to be any closer. Release notes for 4.12 talk about @UseParametersRunnerFactory which looks like it might help, there is also some stuff with the new BlockJUnit4ClassRunnerWithParameters but there doesn't seem to be any example of how to use it.

I could create a "@RunWith(Parameterized.class)" class that feeds 1,2,3,4 into itself but then how to I link the sub-parameterized tests into the JUnit subsystem so it looks nice and provides sensible display.

I hope you can see from my waffle question what I am trying to do I just don't know where to start or if someone else has done this work already?

Out of the box it's not possible to parameterize a JUnit test suite, because both are Runner s and you may only have one @RunWith() annotation at your test.

For that cause I wrote a new Runner that combines the functionality of both to a ParameterizedSuite : https://github.com/PeterWippermann/parameterized-suite Good news is, it also enables you to use @Before and @After !

However, I'm not sure if your problem isn't somewhat different: Don't you have two parameters? You say, you already have a parameterized test and now you wan't to run that test against a list of database configurations. So that would be your second parameter. You would like to test all combinations of those two parameters, wouldn't you?

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