-
-
Notifications
You must be signed in to change notification settings - Fork 945
/
BenchmarkConverterTests.cs
74 lines (59 loc) · 2.01 KB
/
BenchmarkConverterTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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()
{
}
}
}
}