question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimization for NUnit3

See original GitHub issue

The pull request providing the ability to generate fixed name for NUnit3 has just been merged (thanks again @zvirja).

I’m working on a project containing 8,000+ tests. The discovery phase is longer than a minute. In Visual Studio there is a separate process for discovering the tests: during this phase there is no point to create the fixture nor generate the parameter values since they won’t be used (we just generate a test name TestName(auto<string>).

I successfully tested the following:

  1. Have the ability to use a constructor for AutoData that takes a Func<IFixture> parameter instead of IFixture. See this line. For backward compatibility the existing constructor does still exist.
  2. The IFixture factory is only invoked when argument values are required, and argument values are generated only if we are not in a discovery process. See this util type.

Please let me know if this is something that could be merged in this project, in which case I can submit a pull request. Wanted to ask you first before spending time on the pull request.

The outcome I observed is important since the discovery went from more than a minute down to a few seconds.

Let me know

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
frblondincommented, Oct 20, 2017

FYI here is my implementation - just tested succeffully 😃

    public class SkipFixtureWhenDiscoveryMethodBuilder : ITestMethodBuilder
    {
        private const string Discovery = "discovery";

        internal static bool IsDiscovery { get; private set; }

        static SkipFixtureWhenDiscoveryMethodBuilder()
        {
            try
            {
                var processName = Process.GetCurrentProcess().ProcessName;
                IsDiscovery = CultureInfo.InvariantCulture.CompareInfo.IndexOf(processName, Discovery) != -1;
            }
            catch
            {
            }
        }

        private readonly FixedNameTestMethodBuilder _fixedNameBuilder = new FixedNameTestMethodBuilder();

        public virtual TestMethod Build(IMethodInfo method, Test suite, IEnumerable<object> parameterValues, int autoDataStartIndex)
        {
            if (method == null) throw new ArgumentNullException(nameof(method));
            if (parameterValues == null) throw new ArgumentNullException(nameof(parameterValues));

            parameterValues = SkipAutoFixtureParametersIfInDiscovery(method, parameterValues, autoDataStartIndex);
            return _fixedNameBuilder.Build(method, suite, parameterValues, autoDataStartIndex);
        }

        private static IEnumerable<object> SkipAutoFixtureParametersIfInDiscovery(IMethodInfo method, IEnumerable<object> parameterValues, int autoDataStartIndex)
        {
            if (IsDiscovery)
            {
                return parameterValues.Take(autoDataStartIndex) // Only take parameter values that are not managed by AutoFixture
                   .Concat(method.GetParameters().Skip(autoDataStartIndex).Select(_ => default(object)));
            }

            return parameterValues;
        }
    }
0reactions
zvirjacommented, Oct 20, 2017

@frblondin Thanks for sharing your implementation - looks pretty clean. It’s awesome that new AutoFixture API allows you to easily perform such kind of optimizations saving the discovery time! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimizing your NUnit test runs with Launchable
See how to connect Launchable with NUnit's console runner to train a model and get faster test feedback.
Read more >
NickLargen/testcafe-reporter-nunit3: Optimized for Azure ...
This is the NUnit 3 reporter plugin for TestCafe. It currently implements the subset of attributes that Azure DevOps cares about and has...
Read more >
NUnit 3.13.2 Hotfix Release
This release fixes a new issue with the FixtureLifeCycle attribute where IDisposable test fixtures were not being disposed properly.
Read more >
Testing code that could be optimised out
You can disable "Optimize code" in the Properties tab of your unit test project. It's in the Build tab. Share.
Read more >
Getting started with Selenium and NUnit Framework: Tutorial
Step by Step tutorial to create and run NUnit Tests with Selenium. Learn about NUnit Framework with help of examples and sample code....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found