Code Monkey home page Code Monkey logo

Comments (8)

devkhan avatar devkhan commented on July 29, 2024

Update: I digged a bit more and faced a java.lang.IllegalArgumentException: wrong number of arguments in class configuration.

This happened while trying to pass params to @BeforeClass methods.

from junitparams.

jrmichael avatar jrmichael commented on July 29, 2024

JUnitParams supports parameterization only of test methods.

@BeforeClass is meant to be a one time action that is supposed to prepare system for tests. I think parameterizing it is not a good idea.

In your case I would suggest to creata a method that provides all the parameters (file names) and use it in your BeforeClass preparation and as a parameters provider for tests. @Parameters(method="myMethodReturningListOfFiles")

from junitparams.

devkhan avatar devkhan commented on July 29, 2024

I get this, but the issue is if I do this, then all of my tests will repeat the file processing which can be just done at a class(or instance) level. That is why I was initializing members in @BeforeClass.

Anyway, I guess that is by JUnit's design, I'd have to try something else. Thanks.

from junitparams.

jrmichael avatar jrmichael commented on July 29, 2024

Maybe this snippet will help you

@RunWith(JUnitParamsRunner.class)
public class MyTestClass {

    private static File[] files;

    @BeforeClass
    public static void prepareFiles() {
        files = loadMyFiles("file1", "file2");
    }

    public File[] getFiles() {
        return files;
    }

    @Test
    @Parameters(method = "getFiles")
    public void doSomeTesting(File file) {
        //testing...
    }
}

EDIT: this snippet won't work - @BeforeClass is called during test execution and parameters are evaluated earlier

from junitparams.

devkhan avatar devkhan commented on July 29, 2024

Thanks, I'm doing something similar to this. I assume you mean @BeforeClass there (instead of @BeforeEach, right?

from junitparams.

devkhan avatar devkhan commented on July 29, 2024

There's one issue, though. According to your snippet, getFiles is called before prepareFiles defeating the purpose of initializing member variables.

from junitparams.

jrmichael avatar jrmichael commented on July 29, 2024

Oh right.
We cannot call @BeforeClass blocks before parameters calculation. It is a part of test execution, while parameters calculation has to happen earlier in order to establish amount of tests and their description.

Sorry, but you will have to try a different approach.

from junitparams.

devkhan avatar devkhan commented on July 29, 2024

I thought so. For now I'm just using indexes instead of actual objects and initializing them in @BeforeClass like previously.

from junitparams.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.