Giter VIP home page Giter VIP logo

fsharp-hedgehog-xunit's People

Contributors

dharmaturtle avatar johneffo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fsharp-hedgehog-xunit's Issues

Strange behavior when a test method returns Property

This runs, but passes (or perhaps doesn't run at all?) even though it should fail:

[Hedgehog.Xunit.Property]
public Hedgehog.Linq.Property CanUseSelectWithAssertion()
{
    var property =
        from x in ForAll(Gen.Bool)
        select Assert.True(!x);

    return property; // Assume Hedgehog.Xunit will then run the property(?)
}

If I just use the core library, it runs, and fails, as it should:

[Fact]
public void CanUseSelectWithAssertion()
{
    var property =
        from x in ForAll(Gen.Bool)
        select Assert.True(!x);

    property.Check();
}

Both snippets require the following using directives:

using Xunit;
using Hedgehog.Linq;
using static Hedgehog.Linq.Property;

Can Hedgehog.Xunit generate functions?

@dharmaturtle, with @cmeeren we've discussed function generation in the past. Could that work with Hedgehog.Xunit?

using Hedgehog;
using Hedgehog.Xunit;

using System;
using System.Collections.Generic;
using System.Linq;

using Xunit;
using Xunit.Abstractions;

public class Properties
{
    public static Func<Guid, int> Combine(
        Func<Guid, int> f,
        Func<Guid, int> g)
    {
        return x => f(x) + g(x);
    }

    [Property]
    public void CombineIsAssociative(
        Func<Guid, int> f,
        Func<Guid, int> g,
        Func<Guid, int> h,
        Guid guid)
    {
        Assert.Equal(
            Combine(Combine(f, g), h)(guid),
            Combine(f, Combine(g, h))(guid));
    }
}

Output:

System.NotSupportedException:
  Unable to auto-generate System.IntPtr. You can use
  'GenX.defaults |> AutoGenConfig.addGenerator myGen |> GenX.autoWith'
  to generate types not inherently supported by GenX.auto.

Method not found when using Hedgehog 0.12

This example fails when using with Hedgehog 0.12.x but runs fine with Hedgehog 0.11.x

[<Property>]
let ``should be ok``(value : int) =
    value = value

Here is the exception:

System.MissingMethodException
Method not found: 'Int32 Hedgehog.FailureData.get_Size()'.
   at InternalLogic.tryRaise(Report report)
   at XunitOverrides.PropertyTestInvoker.CallTestMethod(Object testClassInstance) in /home/runner/work/fsharp-hedgehog-xunit/fsharp-hedgehog-xunit/src/Hedgehog.Xunit/XunitOverrides.fs:line 11
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_1.<<InvokeTestMethodAsync>b__1>d.MoveNext() in C:\Dev\xunit\xunit\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 257

I checked with using hedgehog-experimental and GenX.auto directly and it works, so the bug must be somewhere in this library.

The following dependencies are used:

"Hedgehog" Version="0.12.1"
"Hedgehog.Xunit" Version="0.3.0"
"xunit" Version="2.4.1"

Recheck executes test way more times than expected

This executes the test once:

    [Fact]
    public void ShouldMap_UserCompetition_Equivalent2()
    {
        var prop =
            from source in ForAll(GenX.autoWith<CompetitionDetailsCache>(CompetitionsAutoGenConfig.Config()))
            select source.ToUserCompetition(Mapper)
                         .Should()
                         .BeEquivalentTo(
                             source.ToUserCompetition());

        prop.ReCheck("50_17003736010433171956_2975322824293632487_000000000000000000101010111110111111011111110111111110111111111101111111111101111111111110111111111111101111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110");
    }

And this executes the test 128667 times, always with the same values:

    [Property, Recheck("50_17003736010433171956_2975322824293632487_000000000000000000101010111110111111011111110111111110111111111101111111111101111111111110111111111111101111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110111111111111111110")]
    public void ShouldMap_UserCompetition_Equivalent(CompetitionDetailsCache source)
    {
        source.ToUserCompetition(Mapper)
              .Should()
              .BeEquivalentTo(source.ToUserCompetition());
    }

Changing a number of tests in Property attribute (I tried [Property(1)]) doesn't seem to have any affect on this behaviour.

Expected: test case is executed once in both cases :)

AutogenConfig specified on multiple levels

Currently we can supply AutoGenConfig on two levels:

  1. Using Properties attribute on a class/module
  2. Using Property attribute on a specific test

Current behaviour is that the config that is specified by Property attribute "wins".

I suggest that we add the ability to "merge" configs so that it'd be possible to supply a bunch of generators with Properties attribute, but the AutoGenConfig that is supplied for an individual test would be "appended" to the upper-level config.

This would probably mean that we make AutoGenConfig a semigroup, which has its own advantages, too.

Is Hedgehog.Xunit mostly useful when there are few test-specific invariants or other requirements for test parameters?

I find that in most of my tests, the set of test parameters have invariants that must be satisfied. For example, the property Foo of the object in the second argument must be larger than the value in first argument. Not to mention that in many tests, values must satisfy some criteria โ€“ for example, a value must be positive in order for the test to make sense.

I am used to the property { ... } computation expression, where I generate one value at a time and can specify the exact requirements for each value. Thess requirements may be based on previously generated values, in order to preserve invariants in the whole set of values.

Based on the readme in this repo, I understand how to accomplish the same with Hedgehog.Xunit using AutoGenConfig. However, if I am to define a separate generator config for more or less every test function, then I don't really see the benefit over simply using property { ... } |> Property.check and generating all values inside there.

Furthermore, to get the same flexibility with Hedgehog.Xunit (specifically, if multiple arguments have the same type but different requirements, such as one positive and one negative integer), I would need to wrap the arguments in a custom type (e.g. a record) to be able to enforce the necessary invariants.

This leads me to believe that Hedgehog.Xunit is mostly useful if one only rarely has test-specific invariants or other requirements for test parameters.

Does that make sense (and do you agree), or have I missed something?

Remove 'xunit' dependency and depend on 'xunit.core' instead?

Does this package need to rely on xunit, and not just xunit.core (or xunit.abstractions, which it currently relies on)?

Asking because I only reference xunit.core v2.4.2 in my test project (it's all I need), but I was then unable to install Hedgehog.Xunit because it tried to install xunit 2.4.1, causing a version conflict. (I was able to work around it by installing xunit 2.4.2 explicitly, but unless Hedgehog.Xunit needs that specific package, it seems unnecessary.)

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.