Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/TestAdapter/Discover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static List<TestCase> ComposeTestCases(string sourceFile)
AppDomain.CurrentDomain.Load(test.GetName());

var typeCandidatesForTests = test.GetTypes()
.Where(x => x.IsClass);
.Where(Helper.IsTestClassCandidate);

foreach (var typeCandidate in typeCandidatesForTests)
{
Expand Down
27 changes: 27 additions & 0 deletions source/TestFrameworkShared/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace nanoFramework.TestFramework
{
/// <summary>
Expand All @@ -10,6 +12,31 @@ public static class Helper
{
private delegate bool AnyDelegateType(object source);

/// <summary>
/// Checks whether a type can be considered for test discovery and execution.
/// </summary>
/// <param name="type">Type to inspect.</param>
/// <returns><see langword="true"/> when the type is a class and not an attribute type.</returns>
public static bool IsTestClassCandidate(Type type)
{
return type.IsClass && !IsAttributeType(type);
}

private static bool IsAttributeType(Type type)
{
var attributeFullName = typeof(Attribute).FullName;

for (var current = type; current != null; current = current.BaseType)
{
if (current.FullName == attributeFullName)
{
return true;
}
}

return false;
}
Comment thread
josesimoes marked this conversation as resolved.

private static bool Any(this object[] array, AnyDelegateType predicate)
{
foreach (var item in array)
Expand Down
2 changes: 1 addition & 1 deletion source/UnitTestLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void Main()

foreach (var type in allTypes)
{
if (!type.IsClass)
if (!Helper.IsTestClassCandidate(type))
{
continue;
}
Expand Down