Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Help in running Junit Test in Junit5 version

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Junit4 Parametized test. I am trying to convert to Junit5 but getting an error on the constructor.

Junit4 ParametizedTest: The below works in JUnit4




when i try to convert the above test to Junit5, i get error on the constructor 'No ParameterResolver registered for parameter [java.lang.String arg0] in constructor BTDriver'.

Below is the JUnit5 Test.




Getting error on the constructor. If i remove the constructor, the values to the below method or null. Not sure how to pass them in.

runInFile(file_, testPattern_, detIdValidation_);

Please help.
 
Sheriff
Posts: 16718
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parameterized tests in JUnit 5 are written differently from how you write them in JUnit 4.

In JUnit 4, you use the constructor to receive each set of parameters. That's all you should be doing in the constructor. Setup should be done via the normal setup methods using @Before and @BeforeClass annotations in JUnit4. In JUnit 5, the equivalent is @BeforeEach and @BeforeAll.

See this article: https://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall

JUnit 5 takes a different approach to parameterized tests, using annotations to specify the source of the parameter values. Each parameterized test method can actually have a different source of its parameters and those values are received by parameters in the test method itself.

Just looking at your test code makes me think there's a basic misunderstanding of how JUnit tests should be written and structured. The fact that you're throwing a RuntimeException from within the test code is evidence of that.
 
Junilu Lacar
Sheriff
Posts: 16718
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a good article that explains parameterized tests in JUnit 5: https://www.baeldung.com/parameterized-tests-junit-5
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic