-
Notifications
You must be signed in to change notification settings - Fork 75
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
Generating objects for combination approval tests #232
Comments
How about this: import org.approvaltests.combinations.CombinationApprovals;
import org.junit.jupiter.api.Test;
public class CoffeeTests {
@Test
void testAllCombinations() {
String[] estates = new String[]{"Attikan", "Other"};
CombinationApprovals.verifyAllCombinations(this::applesauce, estates, Roast.values(),
GrindSize.values());
}
private String applesauce(String estate, Roast roast, GrindSize grindSize) {
Barista barista = new Barista();
Coffee coffee = new Coffee(estate, roast, grindSize);
return barista.make(coffee);
}
class Barista{
public String make(Coffee coffee) {
return "preparing ... " + coffee + " ... done";
}
}
record Coffee(
String estate,
Roast roast,
GrindSize grindSize) {
}
enum Roast {
Light, Medium, Dark
}
enum GrindSize {
Fine, MediumFine, Medium, Coarse
}
} |
Right, this works for simple objects and I use this. What happens when one of the input values to |
ah, so you rather have a separate Combinator and the result of that as 2nd argument then? List<Coffee> listOfAllCombinations = whatYouWant(String type, Roast roast, List<Ingridient> ingrediants ....);
CombinationApprovals.verifyAllCombinations(this::applesauce, listOfAllCombinations); |
I wrote a simple class that can do this at the moment, val coffee = ObjectStream
.of(Coffee::class)
.property("estate", "Attikan")
.property("roast", Roast.Light, Roast.Medium, Roast.Dark)
.property("grindSize", GrindSize.Fine, GrindSize.MediumFine, GrindSize.Medium, GrindSize.Coarse)
.generate()
coffee.onEach(::println)
I want to make sure that I am not wasting my time reinventing the wheel here. Thoughts? |
This way I can configure each individual object and pass them down stream to |
More concrete example, how do we bring functions like these under test, when we have more than 9 input parameters. |
@LarsEckart and @isidore, curious to find out if I am missing something obvious here. If yes, can you folks point me in the right direction? |
Folks, curious to find out if there's a way to do this with Approvals or a different 3rd party library. I checked the public APIs, I wasn't able to find anything. I found a function 9 variation but not the others.
I have an object with x number of parameters and there are y number of objects. How do I generate inputs for them to use with combination approvals. For instance,
My classes
Expected
The text was updated successfully, but these errors were encountered: