Best way to automagically migrate tests from JUnit 3 to JUnit 4?

前端 未结 7 1824
天命终不由人
天命终不由人 2020-11-29 20:14

I have a bunch of JUnit 3 classes which extend TestCase and would like to automatically migrate them to be JUnit4 tests with annotations such as @Before,

7条回答
  •  佛祖请我去吃肉
    2020-11-29 20:59

    If you want to automatically convert your Junit3 tests to Junit4, you can use the Vogella's Codemodify tool, available at this address:

    • https://github.com/vogellacompany/codemodify

    TL;DR install and use it as follows:

    • get Eclipse if you don't use it already (it's open source)
    • From menu: Help > Install new software, then paste the update site http://dl.bintray.com/vogellacompany/junit-4-tools/ in the Work With field
    • Finish the installation, and restart if needed.

    Then, you can right-click any Junit3 test class, and select the Source > Convert to JUnit4 menu entry to convert your class to JUnit4.

    The tool will automagically remove TestCase parent, outdated imports, add @Before, @After, @Test annotations, etc.

提交回复
热议问题