TNG / ArchUnitNET

A C# architecture test library to specify and assert architecture rules in C# for automated testing.
Apache License 2.0
877 stars 57 forks source link

error message improvement #229

Open wolframhaussig opened 6 months ago

wolframhaussig commented 6 months ago

I created a test library with a simple single class:

    public class Class1
    {
        private static object LOCK_OBJECT = new object();
    }

My tests look like this:

    [TestClass]
    public class UnitTest1
    {
        internal static readonly ArchUnitNET.Domain.Architecture ARCHITECTURE = new ArchLoader().LoadAssemblies(
                                            typeof(Class1).Assembly).Build();
        [TestMethod]
        public void TestMethod1()
        {
            Types()
                .That().ResideInNamespace("ClassLibrary1")
                .Should().OnlyDependOn(
                    Types().That().ResideInAssembly("System")
                    )
                .Check(ARCHITECTURE);
        }
    }

This test complains about:

Assert.Fail failed. "Types that reside in namespace with full name "ClassLibrary1" should only depend on Types that reside in assembly with full name "System"" failed: ClassLibrary1.Class1 does depend on System.Object and System.Runtime.CompilerServices.NullableAttribute and ClassLibrary1.Class1

Note that it also complains about system types. When I add .Or().ResideInNamespace("ClassLibrary1"), the test succeeds.

Is it possible to only complain about types that real errors instead of complaining about all references? Or am I missing something?

drewburlingame commented 6 months ago

I've found this annoying as well. The actual errors appear at the end of the message but it's easy to miss this with all the noise.

alexanderlinne commented 1 month ago

Hello @wolframhaussig,

thank you for reporting this issue.

I've now been investigating this and found the following:

I will link this issue as soon as the patch is ready.