Git Product home page Git Product logo

Comments (4)

aivascu avatar aivascu commented on May 26, 2024

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.

mrpmorris avatar mrpmorris commented on May 26, 2024

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.

aivascu avatar aivascu commented on May 26, 2024

@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.

mrpmorris avatar mrpmorris commented on May 26, 2024

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)

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.