Md. Siam Ansary
Md. Siam Ansary

Reputation: 1

How to test the Public Static Void Main method in Java using JUnit 5?

I want to take inputs in the main method , then pass to another that returns a value back to main and print the returned value in main method. I want to do this using JUnit 5.

(I am new to JUnit 5, so, would really appreciate the help.)

Upvotes: 0

Views: 353

Answers (1)

Andrew
Andrew

Reputation: 41

It is considered bad to test static methods because complex static methods themselves are bad and anti-OOP.

You can instead write your logic in a separate class, instantiate an instance of it in your main and use its method.

Then with JUnit 5, test the class' method by instantiating that class and using the method.

Upvotes: 1

Related Questions