Comments (4)
Hi @mrpmorris,
This sounds like an interesting feature request, though I'm not yet sure how it would fit into the current builder API.
This could also potentially have a severe impact on the performance, depending on how it is implemented/used.
For these kind of scenarios I'd usually recommend generating the variations elsewhere and then inject them into the current test case. For example, it should be possible to use a separate method to generate the flags object, and then inject it in other services that might use it.
[Theory]
[MemberAutoData(nameof(FeatureFlagsVariations))]
public void CanGenerateAllPossibleVariations([Frozen] AllPossibleFlagsForThisTest flags, SomeService service1)
{
// Your test code here
}
public static IEnumerable<object[]> FeatureFlagsVariations()
{
// Generate all possible combinations of flags
yield return [new AllPossibleFlagsForThisTest { /* ... */ }];
}
Could you provide more details on this utility that you're using at the moment? Perhaps a snippet of code showing how you're currently implementing the tests, and how do you see AutoFixture helping with that.
from autofixture.
Hi Andrei, thanks for your quick response!
My company is using feature flags. I could simply write a test that says WhenFlagXIsOn_ThenDoesA
and another WhenFlagYIsOn_ThenDoesB
.
But then when someone else is working in the same area and has their own feature flag, I don't want to risk my code breaking because their code did something they didn't think to check for.
I wrote some code like this.
IEnumerable<MyType> allVariations = VariationsBuilder.Create<MyTable>()
.With(x => x.Enabled, [true, false])
.With(x => x.Obsolete, [true, false])
.With(x => x.DeliveryLeadDays, [1, 3, 5, 7])
.Build();
I would then loop through each IEnumerable<MyType> allVariations
and execute the test code. I didn't like this approach so continued to look for a better one.
This morning I was informed of Xunit.Combinatorial
which allows me to do the following
public class UnitTest1
{
[Theory, CombinatorialData]
public void Test1(
[CombinatorialValues] FlagsCombination flags)
{
}
[Theory, CombinatorialData]
public void Test2(
[CombinatorialValues] FlagsCombination flags,
[CombinatorialValues(null, "", " ")] string inputValue)
{
}
public record struct FlagsCombination(bool Is520Enabled, bool Is123Enabled);
}
I thought my approach might be a nice addition to AutoFixture so offered to add it. Although I no longer need it just for flag combinations I thought it might be useful for building data like this
IEnumerable<Person> = fixture.CreateVariations<Person>()
.With(x => x.GivenName, ["Bob", "Peter", "Fred"])
.With(x => x.FamilyName, ["Monkhouse", "Pan", "Flintstone"])
.With(x => x.Age, [5, 25, 55]);
Maybe for building large data sets or something?
from autofixture.
@mrpmorris can you provide the code of the variations generator?
I must warn you though, that you must be the legal owner of the code you're contributing. From what you mentioned so far, it seems that you wrote the implementation for work. Please before sharing any more code ensure that you are not in breach of any contract.
from autofixture.
The code I shared was the interface to consume the code rather than the code itself.
I got chat gpt to write something that was "good enough for now", but I had an idea for a better implementation that I intended to write in my own time.
After posting here I got impatient and wrote my better idea whilst working for them, so now I'll have to ask if they'd be willing to contribute it.
I'll let you know what they say.
I'm sorry for my impatience :)
from autofixture.
Related Issues (20)
- ✨ Repeatable random numbers
- 🐛 [AutoFixture.Xunit2] MemberAutoDataAttribute generates fixtures for test method parameters provided from MemberData HOT 3
- 🐛 Enum data type is not applied when a member has both `[StringLength]` and `[EnumDataType]` annotations HOT 4
- 🐛 Unexpected ObjectCreationExceptionWithPath or if not a bug at least a confusing description HOT 3
- ✨ Support FakeItEasy 8 HOT 1
- ✨ Support for NUnit 4 HOT 16
- 🐛 FromFactory doesn't honor the Range attribute HOT 6
- ✨ Accept `ISpecimentBuilder` as value generator for `With` HOT 1
- ✨ DataAnnotations support for specimen factories
- 🐛 Auto properties on large record types causes severe performance degradation HOT 4
- ICustomization for DateOnly causes a hang. HOT 1
- 🐛 RandomNumericSequenceGenerator with limits, can create values outside of these limits in certain scenarios HOT 1
- autofixture is missing NuGet package README file HOT 2
- autofixture.automoq is missing NuGet package README file HOT 1
- `IAsyncEnumerable` generates an infinite sequence 🐛 HOT 2
- 🐛 SourceLink doesn't work because of incorrect casing in GitHub URLs HOT 4
- 🚨 Vulnerability in packages System.Net.Http and System.Text.RegularExpressions HOT 3
- 🐛 FromSeed() does not set value from seeded object property HOT 4
- Not able to create second nullalbe int 🐛
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autofixture.