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

#495 - Unit test for reading attributes from the base class #514

Merged
merged 2 commits into from Aug 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions tests/BenchmarkDotNet.Tests/Running/BenchmarkConverterTests.cs
@@ -0,0 +1,74 @@
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Xunit;

namespace BenchmarkDotNet.Tests.Running
{
public class BenchmarkConverterTests
{
/// <summary>
/// https://github.com/dotnet/BenchmarkDotNet/issues/495
/// </summary>
[Fact]
public void ReadsAttributesFromBaseClass()
{
var derivedType = typeof(Derived);
Benchmark benchmark = BenchmarkConverter.TypeToBenchmarks(derivedType).Single();

Assert.NotNull(benchmark);
Assert.NotNull(benchmark.Target);

Assert.NotNull(benchmark.Target.IterationSetupMethod);
Assert.Equal(benchmark.Target.IterationSetupMethod.DeclaringType, derivedType);

Assert.NotNull(benchmark.Target.IterationCleanupMethod);
Assert.Equal(benchmark.Target.IterationCleanupMethod.DeclaringType, derivedType);

Assert.NotNull(benchmark.Target.GlobalCleanupMethod);
Assert.Equal(benchmark.Target.GlobalCleanupMethod.DeclaringType, derivedType);

Assert.NotNull(benchmark.Target.GlobalSetupMethod);
Assert.Equal(benchmark.Target.GlobalSetupMethod.DeclaringType, derivedType);
}

public abstract class Base
{
[GlobalSetup]
public abstract void GlobalSetup();

[GlobalCleanup]
public abstract void GlobalCleanup();

[IterationSetup]
public abstract void Setup();

[IterationCleanup]
public abstract void Cleanup();

[Benchmark]
public void Test()
{
}
}

public class Derived : Base
{
public override void GlobalSetup()
{
}

public override void GlobalCleanup()
{
}

public override void Setup()
{
}

public override void Cleanup()
{
}
}
}
}