Skip to content
Advertisement

parameterized test constructor of junit java error message: Test class should have exactly one public zero-argument constructor

I can really use some help with this parameterized test case I am trying to create. No matter what kind of constructor I create the IDE gives an error message. Here is my code:

JavaScript

I have tried different ways of creating a 1 parameter, 2, and no parameter constructors. But I have never seen this type of issue or what the solution might be. I am following this link and this tutorial. This is my first parameterized test, and debug does not seem to provide much for me either. I also saw these links, but they did not help. I can provide the code for the rest of the project also on GitHub or gist. I did debug my code through creating the fileList properly, but I know little about what happens to it afterwards or what needs to happen. Here is an excerpt of the error:

JavaScript

Here is the latest version of my code:

JavaScript

Here is a pic of the debug session showing everything I want in the file list. Some how the board object does not transfer to my Solver constructor. enter image description here

Advertisement

Answer

Debug Capture Here is what the no-arg constructor error means.

The constructor in the test class is the following:

JavaScript

That takes 2 arguments, so is not a no-arg constructor. The following is a no-arg constructor:

JavaScript

Removing the 2-arg constructor will work, so this does not need to be explicitly listed, because the java compiler will add the default no-arg constructor automatically.

HOWEVER the reason for the error is a mix of 2 approaches for the Parameterized test class.

EITHER use a no-arg constructor with the @Parameterized.Parameters fields (which need to be public and not private, by the way), OR remove those fields and use the construct with arguments that take the parameters.

Here is the code modified to use the first approach (that is, with the @Parameterized.Parameters fields):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement