Code Monkey home page Code Monkey logo

Comments (4)

michal-lipski avatar michal-lipski commented on July 29, 2024

You can define method that will provide parameters for your test:

    @Test
    @Parameters
    public void params_in_default_method(String p1, Integer p2) { }
    private Object parametersForParams_in_default_method() {
        return new Object[]{new Object[]{"AAA", 1}, new Object[]{"BBB", 2}};
    }

    @Test
    @Parameters(method = "named1")
    public void params_in_named_method(String p1, Integer p2) { }
    private Object named1() {
        return new Object[]{"AAA", 1};
    }

Check: https://github.com/Pragmatists/JUnitParams/blob/master/src/test/java/junitparams/usage/Samples_of_Usage_Test.java

from junitparams.

ChrisArrington avatar ChrisArrington commented on July 29, 2024

I have a question/concern along these lines. In my case I'm using some immutable objects with values pre-set to be returned for certain getter methods. I typically create an instance of the objects in the constructor of my test, storing it as an instance variable in the test class. On each instance I initialize each getter methods to return a random value, which I also keep as instance variables. In each of my test methods the I can compare the results from the test with the appropriate instance variable value. This technique currently doesn't work in JUnitParams because the instance of the test class used to initialize the cached parameters is different from the one used to run the actual test.

I know that one solution to this would be to not use randomized values, but I'd rather not use hard coded values. This basically comes down to being able to use instance variables in your parameter methods.

Looking through the code I thought one way it could be done would be to somehow optionally set the cached parameters just before the test is run, or always set the parameters at this time. Maybe this could be done with a certain annotation or annotation parameter.

from junitparams.

grzesuav avatar grzesuav commented on July 29, 2024

@ChrisArrington wouldn't be possible to extract those instance fields as additional parameters ?

Could you post an example code to be sure that we are on the same page ?

from junitparams.

zbychupragmatists avatar zbychupragmatists commented on July 29, 2024

Closing because @ChrisArrington is not answering. If you have any more doubts - please open new issue.

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.