Skip to content

Commit 7c333e5

Browse files
Add documentation and minimal examples for differences between testing in Debug mode and testing in Release mode.
Signed-off-by: GeorgKreuzmayr <g.kreuzmayr@gmail.com>
1 parent 2c0cd37 commit 7c333e5

3 files changed

Lines changed: 90 additions & 1 deletion

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2019 Florian Gather <florian.gather@tngtech.com>
2+
// Copyright 2019 Fritz Brandhuber <fritz.brandhuber@tngtech.com>
3+
// Copyright 2020 Pavel Fischer <rubbiroid@gmail.com>
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
using System.Linq;
9+
using ArchUnitNET.Domain;
10+
using ArchUnitNET.Domain.Extensions;
11+
using ArchUnitNET.Loader;
12+
using Xunit;
13+
14+
namespace ExampleTest
15+
{
16+
public class LimitationsOnReleaseTest
17+
{
18+
private static readonly Architecture Architecture =
19+
new ArchLoader().LoadAssembly(typeof(LimitationsOnReleaseTest).Assembly).Build();
20+
21+
private static IType _edgeCaseDataClass = Architecture.GetClassOfType(typeof(EdgeCaseData));
22+
private static IType _missingDependencyClass = Architecture.GetClassOfType(typeof(MissingDependencyClass));
23+
24+
[Fact]
25+
public void CastTest()
26+
{
27+
var typeDependencies = _edgeCaseDataClass.Members
28+
.Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithCastDependency))).ToList().First()
29+
.GetTypeDependencies().ToList();
30+
31+
Assert.Contains(_missingDependencyClass, typeDependencies);
32+
}
33+
34+
[Fact]
35+
public void NullVariableTest()
36+
{
37+
var methodWithCastDependencyDependencies = _edgeCaseDataClass.Members
38+
.Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithNullVariable))).ToList().First()
39+
.GetTypeDependencies().ToList();
40+
41+
Assert.Contains(_missingDependencyClass, methodWithCastDependencyDependencies);
42+
}
43+
44+
[Fact]
45+
public void TypeOfDependencyTest()
46+
{
47+
var methodWithTypeOfDependencyDependencies = _edgeCaseDataClass.Members
48+
.Where(t => t.FullName.Contains(nameof(EdgeCaseData.MethodWithTypeOfDependency))).ToList().First()
49+
.GetTypeDependencies().ToList();
50+
51+
Assert.Contains(_missingDependencyClass, methodWithTypeOfDependencyDependencies);
52+
}
53+
}
54+
55+
internal class EdgeCaseData
56+
{
57+
public void MethodWithTypeOfDependency()
58+
{
59+
var a = typeof(MissingDependencyClass);
60+
}
61+
public void MethodWithCastDependency()
62+
{
63+
var a = (MissingDependencyClass) new SubClass();
64+
}
65+
66+
public void MethodWithNullVariable()
67+
{
68+
MissingDependencyClass a = null;
69+
}
70+
}
71+
internal class MissingDependencyClass
72+
{
73+
}
74+
internal class SubClass : MissingDependencyClass
75+
{
76+
}
77+
}

documentation/docs/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ Here you can find the full API of ArchUnitNET.
3636

3737
## Limitations
3838

39-
* [Constant Fields] (limitations/constant_fields.md)
39+
* [Debug Artifacts](limitations/debug_artifacts.md)
40+
* [Constant Fields](limitations/constant_fields.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
##Debug Artifacts
2+
ArchUnitNET gathers information about the architecture from analyzing
3+
binaries, therefore running tests with the Release option (`dotnet test -c Release`) instead of the Debug
4+
option (`dotnet test -c Debug`) can lead to not finding dependencies you normally would expect to find.
5+
The edge cases we so far found are not initializing a local variable, casting an object and using
6+
the typeof() statement. A minimal example for each edge case can be found [here](https://github.com/TNG/ArchUnitNET/blob/master/ExampleTest/LimitationsOnReleaseTest.cs).
7+
8+
9+
If you come across another edge case, where executing tests in Debug mode leads to other results than executing
10+
tests in Release mode, let us know via a [github issue](https://github.com/TNG/ArchUnitNET/issues).
11+

0 commit comments

Comments
 (0)