Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1k
Description
According tothe docs forArgumentsSource:
The source must be within benchmarked type!
It would be nice to lift this restriction. The attribute constructor could have an overload that takes aType parameter.
For example, NUnit'sTestCaseSource does this.
A common pattern in my code is that I have one class which defines all the different cases that a method might encounter. I feed the results of this class into both my unit tests and my benchmarks, to test each case for both correctness and performance. Currently, my benchmark code is bloated with methods that just return immediately with the result of a method in the cases class, which I need to do becauseArgumentsSource can't directly access the method I want to use for the arguments. I would love to be able to remove all those methods.
Example code as it currently is:
[Benchmark][ArgumentsSource(nameof(MethodACases))]publicMethodAResultsBenchmarkMethodA(MethodACase@case)=>CodeBeingBenchmarked.MethodA(@case.Param1,@case.Param2,@case.Param3);publicstaticIEnumerable<MethodACase>MethodACases()=>DiagnosticsCases.MethodACases();
Example code as I propose it ought to be:
[Benchmark][ArgumentsSource(typeof(DiagnosticsCases),nameof(DiagnosticsCases.MethodACases))]publicMethodAResultsBenchmarkMethodA(MethodACase@case)=>CodeBeingBenchmarked.MethodA(@case.Param1,@case.Param2,@case.Param3);