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.

Benchmark not run in MS Test test class

See original GitHub issue

Given the following test class in MS Test:

[TestClass]
public class TestBenchmarkDotNet
{
    [TestMethod]
    public void Test()
    {
        BenchmarkRunner.Run<TestBenchmarkDotNet>();
    }

    [Benchmark]
    public void Benchmark()
    {
        Thread.Sleep(5000);
    }
}

Running Test() from the Visual Studio test runner will not trigger the benchmark method at all, neither in Release or in Debug mode. Is this scenario supported?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
mms-commented, Jul 29, 2016

@adamsitnik Agree 😃 Especially now that VS 2015 seems to be using just as much CPU as the unit test while it’s running.

But it still has merit. I’m referring to code refactoring with performance as a goal. Meaning you have old code and new code and want to compare what is faster, all the while you need to maintain correctness. Since tests will be updated anyway when this happens you might as well get feedback on performance.

That is often before one does a serious benchmark on a ready piece of code there is a period (usually long) of experimentation to see what gives better results, a guided search if you will. Accuracy of the benchmark does not matter here just the direction, is it faster or not. Getting this info from the IDE would increase productivity, weather through unit tests or some one other VS panel. Perhaps this is something the Visual Studio team could integrate.

1reaction
ig-sinicyncommented, Aug 2, 2016

@adamsitnik We’ve integration with nUnit, xUnit and MsTest. xUnit one is quite lame (waiting for https://github.com/xunit/xunit/issues/908), others two work fine. I’m on vacation this week, so no new commits for some time, sorry 😃

About accuracy. As @mms wrote there’s actually no need in accuracy in unit tests. The thing you want is not accuracy but repeatability. Same code should produce same results on different runs, different machines and on different environments. If this is false the entire thing is failed. We have our tests running on appveyor CI, local buildserver, dev machines, ultrabooks and even tablets. No failures:)

* Of course, all above is true for “common” benchmarks, those that depend hardly on CPU features, memory available or on IO latency will require same-level hardware to get similar results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tests not running in Test Explorer - visual studio
The Test Explorer is showing all unit tests, but once clicking on "Run All", all tests are getting greyed out and show no...
Read more >
Make Microsoft Run Benchmark Tests for You
Benchmarking is important! Problem is running those tests can make your machine unusable. Let's make Microsoft and GitHub feel that pain ...
Read more >
Unit testing fundamentals - Visual Studio (Windows)
Learn how Visual Studio Test Explorer provides a flexible and efficient way to run your unit tests and view their results.
Read more >
How to Benchmark Testing your code in C# - Maytham Fahmi
Lets create class CodeToBeBenchmark and say we have 2 fancy method for hash calculation, no thing special. One to calculate MD5 hashing and...
Read more >
Qt Test Overview
Qt Test needs no special test-runners; no special registration for tests. Data-driven testing, A test can be executed multiple times with different test...
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