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

Support for NUnit TestContext.AddFormatter #595

Open
jakob-ledermann opened this issue Sep 21, 2021 · 3 comments
Open

Support for NUnit TestContext.AddFormatter #595

jakob-ledermann opened this issue Sep 21, 2021 · 3 comments

Comments

@jakob-ledermann
Copy link

Would it be possible to support NUnits ValueFormatters configured with TestContext.AddFormatter für FsCheck.Nunit tests?

@kurtschelfthout
Copy link
Member

Could you give an example of what you’d like to see working, but doesn’t currently?

Also to manage expectations: on FsCheck.NUnit I am happy to take PRs but unlikely to write any new features myself.

@jakob-ledermann
Copy link
Author

Thank you for the heads up. Let me explain my problem:
`
sealed class Custom_Type {
public int ID {get;set;}
public string Name {get;set;}

public override string ToString() => "Insufficient Information to identify Data";

}

public void Setup() {
TestContext.AddFormatter(x => $"CustomType: (Id: {((Custom_Type)x).Id}, Name: {((Custom_Type)x).Name})"
}

[Property( ... )]
public Property Sample_with_custom_type(Custom_Type arg) {
Assert.Fail();
}
With the current Versions I see the following message:
Falsifiable, after 1 test (0 shrinks) (StdGen (649505996,296942915)):
Original:
Insufficient Information to identify Data
`

Instead I would prefer to see the following message:
Falsifiable, after 1 test (0 shrinks) (StdGen (649505996,296942915)): Original: CustomType: (Id: {((Custom_Type)x).Id}, Name: {((Custom_Type)x).Name})

If there is a way to achieve the second error message in this case with some configuration for FsCheck.Core I think I can integrate an adapter to the NUnit Custom formatters into FsCheck.NUnit.

@kurtschelfthout
Copy link
Member

Yes I think this should be doable - again caveat my knowledge about NUnit is limited - but it seems like that should be a matter of routing FsCheck's output through NUnit's output system somehow: https://github.com/fscheck/FsCheck/blob/master/src/FsCheck.NUnit/FsCheckPropertyAttribute.fs#L25

We do a similar thing for FsCheck.Xunit, which has a ITestOutputHelper we write to.

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

2 participants