How to parameterize junit Test Suite

后端 未结 7 1950
梦毁少年i
梦毁少年i 2021-01-14 06:42

Is it possible to parameterize a TestSuite in junit 4 ?

For declaring a class as a test suite I need the annotation @RunWith(Suite.class), but the same

7条回答
  •  梦毁少年i
    2021-01-14 07:21

    I agree, it's not possible with the provided classes, but there are workarounds that will get you most of the way there, like @mikemil's.

    I've spent some time extending Suite and delegating to Parameterized, with partial success; it is possible to build runner that does what you want, and the code is more-or-less written for you in those two classes. The way those classes interact (in particular, the definition of Parameterized#getChildren()) makes it difficult to extend or delegate to those classes to accomplish what you need, but creating a whole new class than extends ParentRunner and lifts code from the other two would be fairly easy.

    I'll try to get more time to come back to this later. If you do build a new runner before I get around to it, please post it as an answer, I'd love to use it myself.

提交回复
热议问题