dolphinscheduler icon indicating copy to clipboard operation
dolphinscheduler copied to clipboard

[Improvement][UT] Upgrade junit to 5.+

Open ruanwenjun opened this issue 1 year ago • 13 comments

Search before asking

  • [X] I had searched in the issues and found no similar feature requirement.

Description

Right now, we still use junit 4.+ in our repo, I hope we can upgrade to Junit 5.+, then we can easy to write the UT, JUnit 5 provide some useful feature, e.g. assertThrow, assertTimeout ...

Are you willing to submit a PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

ruanwenjun avatar Jul 14 '22 10:07 ruanwenjun

cc #10573

ruanwenjun avatar Jul 14 '22 10:07 ruanwenjun

Thank you for your feedback, we have received your issue, Please wait patiently for a reply.

  • In order for us to understand your request as soon as possible, please provide detailed information、version or pictures.
  • If you haven't received a reply for a long time, you can join our slack and send your question to channel #troubleshooting

github-actions[bot] avatar Jul 14 '22 10:07 github-actions[bot]

What about using TestNG?

EricGao888 avatar Jul 23 '22 03:07 EricGao888

What about using TestNG?

This may need to refactor all test code, if we want to use TestNG to replace Junit

ruanwenjun avatar Jul 23 '22 10:07 ruanwenjun

What about using TestNG?

This may need to refactor all test code, if we want to use TestNG to replace Junit

@ruanwenjun Yes. At this moment, I think we have about 4 people, me and my colleagues who will work on the UT refactoring. It is possible for us to refactor all test code and fix all related style / formatting issues. The question lying between choosing TestNG and jUnit is whether it is necessary to replace one with another. So far, I've found some advantages of TestNG over jUnit:

  • TestNG supports running UT in parallelism.
  • TestNG supports testing group.
  • TestNG supports an easier way to pass data into testing method using Data Provider.
  • TestNG supports Dependency Test.
  • TestNG supports Parameterization through xml configuration.

Some related materials:

  • https://www.youtube.com/watch?v=OWXWQE4pL_0
  • https://www.guru99.com/junit-vs-testng.html

Although TestNG is more powerful, it seems that it is not a must to switch jUnit to TestNG 🤣

WDYT?

EricGao888 avatar Jul 23 '22 13:07 EricGao888

What about using TestNG?

This may need to refactor all test code, if we want to use TestNG to replace Junit

@ruanwenjun Yes. At this moment, I think we have about 4 people, me and my colleagues who will work on the UT refactoring. It is possible for us to refactor all test code and fix all related style / formatting issues. The question lying between choosing TestNG and jUnit is whether it is necessary to replace one with another. So far, I've found some advantages of TestNG over jUnit:

  • TestNG supports running UT in parallelism.
  • TestNG supports testing group.
  • TestNG supports an easier way to pass data into testing method using Data Provider.
  • TestNG supports Dependency Test.
  • TestNG supports Parameterization through xml configuration.

Some related materials:

  • https://www.youtube.com/watch?v=OWXWQE4pL_0
  • https://www.guru99.com/junit-vs-testng.html

Although TestNG is more powerful, it seems that it is not a must to switch jUnit to TestNG 🤣

WDYT?

If we choose not to switch jUnit to TestNG, I support upgrading jUnit to 5.+

EricGao888 avatar Jul 23 '22 13:07 EricGao888

What about using TestNG?

This may need to refactor all test code, if we want to use TestNG to replace Junit

@ruanwenjun Yes. At this moment, I think we have about 4 people, me and my colleagues who will work on the UT refactoring. It is possible for us to refactor all test code and fix all related style / formatting issues. The question lying between choosing TestNG and jUnit is whether it is necessary to replace one with another. So far, I've found some advantages of TestNG over jUnit:

  • TestNG supports running UT in parallelism.
  • TestNG supports testing group.
  • TestNG supports an easier way to pass data into testing method using Data Provider.
  • TestNG supports Dependency Test.
  • TestNG supports Parameterization through xml configuration.

Some related materials:

  • https://www.youtube.com/watch?v=OWXWQE4pL_0
  • https://www.guru99.com/junit-vs-testng.html

Although TestNG is more powerful, it seems that it is not a must to switch jUnit to TestNG 🤣

WDYT?

AFAIK, Junit5+ can support these features.

ruanwenjun avatar Jul 24 '22 02:07 ruanwenjun

What about using TestNG?

This may need to refactor all test code, if we want to use TestNG to replace Junit

@ruanwenjun Yes. At this moment, I think we have about 4 people, me and my colleagues who will work on the UT refactoring. It is possible for us to refactor all test code and fix all related style / formatting issues. The question lying between choosing TestNG and jUnit is whether it is necessary to replace one with another. So far, I've found some advantages of TestNG over jUnit:

  • TestNG supports running UT in parallelism.
  • TestNG supports testing group.
  • TestNG supports an easier way to pass data into testing method using Data Provider.
  • TestNG supports Dependency Test.
  • TestNG supports Parameterization through xml configuration.

Some related materials:

  • https://www.youtube.com/watch?v=OWXWQE4pL_0
  • https://www.guru99.com/junit-vs-testng.html

Although TestNG is more powerful, it seems that it is not a must to switch jUnit to TestNG 🤣 WDYT?

AFAIK, Junit5+ can support these features.

@ruanwenjun Sounds good to me. I will take this issue.

I found a post about differences between jUnit4 and jUnit5, as well as how to migrate: https://blogs.oracle.com/javamagazine/post/migrating-from-junit-4-to-junit-5-important-differences-and-benefits

EricGao888 avatar Jul 24 '22 02:07 EricGao888

Great! It seems use Junit5+ can achieve the same with less change.

caishunfeng avatar Jul 26 '22 01:07 caishunfeng

I'm working on this, will submit a PR tomorrow or next week.

EricGao888 avatar Aug 06 '22 03:08 EricGao888

In DolphinScheduler, we sometimes use Powermock for UTs. However, it seems Powermock does not and will not support jUnit 5. https://github.com/powermock/powermock/issues/929

EricGao888 avatar Aug 07 '22 15:08 EricGao888

In DolphinScheduler, we sometimes use Powermock for UTs. However, it seems Powermock does not and will not support jUnit 5. powermock/powermock#929

Can we use Mokito to replace powermock?

ruanwenjun avatar Aug 08 '22 02:08 ruanwenjun

In DolphinScheduler, we sometimes use Powermock for UTs. However, it seems Powermock does not and will not support jUnit 5. powermock/powermock#929

Can we use Mokito to replace powermock?

Seems powermock helps mock the static, private and final methods more easily. Anyway I will look into it and see whether there is a way to use mockito to replace powermock.

EricGao888 avatar Aug 08 '22 07:08 EricGao888

In DolphinScheduler, we sometimes use Powermock for UTs. However, it seems Powermock does not and will not support jUnit 5. powermock/powermock#929

Can we use Mokito to replace powermock?

Seems powermock helps mock the static, private and final methods more easily. Anyway I will look into it and see whether there is a way to use mockito to replace powermock.

If we can find the alternative or the method to do it, we can get rid of it

zhongjiajie avatar Aug 15 '22 07:08 zhongjiajie