Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide random values #49

Open
nipafx opened this issue May 22, 2017 · 15 comments
Open

Provide random values #49

nipafx opened this issue May 22, 2017 · 15 comments

Comments

@nipafx
Copy link
Member

nipafx commented May 22, 2017

Support use cases for random values, e.g. as parameters (like this; inspired by junit-team/junit5#839) or fields or arguments for parameterized tests.

@nipafx nipafx changed the title Support random values Provide random values May 22, 2017
@nipafx nipafx added the ⚙️ component: Jupiter Issues coming from (internal/official) Jupiter features etc. label Jan 21, 2018
@sormuras
Copy link
Member

sormuras commented May 2, 2018

And/or as a simple ParameterResolver implementation show-cased by the junit5-sample:

Usage could look like:

@ExtendWith(RandomParametersExtension.class)
class RandomParametersExtensionTests {
  @Test
  void injectsInteger(@Random int i, @Random int j) { assertNotEquals(i, j); }
  @Test
  void injectsDouble(@Random double d) { assertEquals(0.0, d, 1.0); }
}

@nipafx
Copy link
Member Author

nipafx commented May 8, 2018

My personal opinion is that however this is implemented, it should be possible to repeat the tests with the same random values. That makes it necessary:

  • to have a deterministic entry point that spits out the seed value that is used
  • to allow configuration of that entry point to pass the seed to it

As far as I see it (and as long as JUnit does not randomize test order), the only challenge for the deterministic entry point is multi-threading. I am willing to accept that limitation.

Speaking of randomizing test order, it would be interesting to find out whether an extension could do that.

@sormuras
Copy link
Member

sormuras commented May 8, 2018

[...] repeat the tests with the same random values.

@Random(seed = 123) should suffice. When running with the default @Random it could be reported via the TestReporter facility.

Speaking of randomizing test order, it would be interesting to find out whether an extension could do that.

junit-team/junit5#13 is still open...

@nipafx
Copy link
Member Author

nipafx commented Jul 29, 2018

Possible features:

  • set seed per class
  • set seed globally via configuration parameter

@Michael1993
Copy link
Member

Michael1993 commented Apr 12, 2020

I don't see the use-case for this. You should always control your input to your tests which means no randomizing.

@Bukama Bukama added 📖 theme: extensions 🏗️ type: new feature and removed ⚙️ component: Jupiter Issues coming from (internal/official) Jupiter features etc. 🏗️ type: enhancement labels May 9, 2020
@Bukama
Copy link
Member

Bukama commented Jun 21, 2020

I don't see the use-case for this. You should always control your input to your tests which means no randomizing.

I'm with @Michael1993.

  • If I don't need a value for my method I can pass whatever class type of the parameter / class under test allows (null, default, any number, etc.)
  • If I want to check for edge cases code coverage tools like JaCoCo or mutation testing tools like PIT take this spot
  • If I really want to use random values, we don't have to reinvent the wheel, as there are plenty of property based testing tools like jqwik

So I vote to close this issue.

@beatngu13
Copy link
Member

I don't see the use-case for this. You should always control your input to your tests which means no randomizing.

Actually, random testing is quite a big thing. Be it at the top of the test automation pyramid (e.g. Sapienz) or at the bottom (e.g. QuickCheck).

However, let's not get too philosophical. 😉 I agree with @Bukama that we shouldn't do this, there are excellent libs already available. I think this is out of scope and would open a can of worms. Therefore, I also vote to close this issue.

@nipafx
Copy link
Member Author

nipafx commented Jun 22, 2020

Whoa, why does everybody want to close this? No random values in tests? Where's your sense of adventure? 🚀

I'd still like to implement this eventually:

  • there is an actual JUnit user asking for this feature
  • with a seed, the randomness is reproducible, so there's no disadvantage
  • switching to a different test engine or even entire testing tool has a slightly bigger foot print than adding an extension
  • it sounds like fun!

Vote not to close 😜

@nipafx
Copy link
Member Author

nipafx commented Jun 22, 2020

I say never be complete, I say stop being perfect, I say let... lets evolve, let the chips fall where they may.

Introduce a little anarchy. Upset the established order and everything becomes chaos. I'm an agent of chaos. Oh, and you know the thing about chaos? It's fair.

Why so serious? 🃏

Yes, quoting Tyler Durden and the Joker is juvenile and both are full of shit, but... it's fun. :)

@nipafx
Copy link
Member Author

nipafx commented Oct 27, 2020

I also just now realize that it may be interesting to think about this in terms of parameterized tests:

  • this could be a source for parameterized test arguments
  • this could be a test template of its own, spawning a preconfigured number of tests with random parameters

I'm gonna unilaterally green-light this. 😁

@nipafx
Copy link
Member Author

nipafx commented Apr 13, 2021

To be a good issue for first contributors, this issue should describe the specific annotations to be created as well as give a rough idea how to implement them.

@nipafx nipafx added this to Improve in Up for grabs... Apr 13, 2021
@keturn
Copy link

keturn commented May 4, 2021

When you get to the point of wanting to have reproducible runs, this looks like it might be of use: java.util.SplittableRandom

@nipafx
Copy link
Member Author

nipafx commented May 4, 2021

In lieu of fleshing out this issue, I created a proof of concept. 😁

@nipafx
Copy link
Member Author

nipafx commented May 27, 2021

I think the best use for this extension is to become part of the revamped Cartesian product extension, so I don't think it makes sense to invest more time here before #415 is done.

@nipafx nipafx added ⚙️ component: Pioneer Issues about Pioneer own things (e.g. utils) 🚦 status: blocked and removed 🚦 status: triaged labels May 27, 2021
@nipafx nipafx removed this from Improve / Discuss in Up for grabs... May 27, 2021
@tubbynl
Copy link

tubbynl commented Oct 3, 2023

In randomizing data JavaFaker (https://github.com/DiUS/java-faker) does provide sensible random data, in combination with parameterized tests you do get valuable edge-case information.

Certainly when testing validation stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants