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

Allow discovering test methods from base class in different assembly #147

Merged
merged 5 commits into from
Apr 11, 2017

Conversation

ajryan
Copy link
Contributor

@ajryan ajryan commented Apr 9, 2017

Fixes issue #23

@msftclas
Copy link

msftclas commented Apr 9, 2017

@ajryan,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@msftclas
Copy link

msftclas commented Apr 9, 2017

@ajryan, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

Assert.IsNotNull(tests);
Assert.AreEqual(methodCount, tests.Count);
Assert.IsTrue(tests.Any(t => t.TestMethod.Name == "BaseTestMethod"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.IsTrue(tests.Any(t => t.TestMethod.Name == "BaseTestMethod")); [](start = 12, length = 69)

Do add a message on assertion failure so it is easy to identify why this test failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do for all test methods I've changed/added.


var tests = typeEnumerator.Enumerate(out this.warnings);

Assert.IsTrue(tests.All(t => t.TestMethod.Name != "BaseTestMethod"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.TestMethod.Name != "BaseTestMethod" [](start = 41, length = 37)

add a contains check instead.

Copy link
Contributor Author

@ajryan ajryan Apr 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that work? tests.Contains would expect an instance of UnitTestElement and that doesn't implement equality members, nor does TestMethod...

@@ -97,8 +97,10 @@ internal Collection<UnitTestElement> GetTests(ICollection<string> warnings)
// Test class is already valid. Verify methods.
foreach (var method in this.type.GetRuntimeMethods())
{
// Todo: Provide settings to allow users to pick up tests from other assemblies as well.
if (!method.DeclaringType.GetTypeInfo().Assembly.Equals(this.type.GetTypeInfo().Assembly))
var isMethodDeclaredInTestTypeAssembly = method.DeclaringType.GetTypeInfo().Assembly.Equals(this.type.GetTypeInfo().Assembly);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method.DeclaringType.GetTypeInfo().Assembly.Equals(this.type.GetTypeInfo().Assembly) [](start = 57, length = 84)

This seems to be causing issues in testability. How about putting this in a separate API in reflecthelper and mocking that out in your tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, will do.

@@ -238,6 +245,16 @@ private static MSTestSettings ToSettings(XmlReader reader)
break;
}

case "ENABLEBASECLASSTESTMETHODSFROMOTHERASSEMBLIES":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENABLEBASECLASSTESTMETHODSFROMOTHERASSEMBLIES [](start = 30, length = 45)

can we add tests for this too please? you would find them under MSTest.CoreAdapter.Unit.Tests -> MSTestSettingsTests.cs

Copy link
Contributor Author

@ajryan ajryan Apr 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@AbhitejJohn
Copy link
Contributor

Thanks a bunch for getting this fixed quickly @ajryan. Had a few comments. Will push this in as soon as they are resolved.

@AbhitejJohn
Copy link
Contributor

@pvlakshm should this be turned on by default(searching for test methods in a base class defined in another assembly) given that this is a common scenario?

@ajryan
Copy link
Contributor Author

ajryan commented Apr 11, 2017

Thanks for the quick review! I'll have a revision soon. Please see my question above about the Contains thing too...

@ajryan
Copy link
Contributor Author

ajryan commented Apr 11, 2017

This should be ready except for the comment about using Contains

@AbhitejJohn
Copy link
Contributor

@ajryan : I meant contains for the name "BaseTestMethod". Thinking again, I think we already do this in multiple other places. This shouldn't be a problem. Merging this change.
Thanks for the contribution :)
/cc @sbaid @pvlakshm

@AbhitejJohn AbhitejJohn merged commit 42928ca into microsoft:master Apr 11, 2017
@ajryan
Copy link
Contributor Author

ajryan commented Apr 11, 2017

Awesome, thanks for reviewing and merging so quickly! 🎉

@AbhitejJohn
Copy link
Contributor

Pleasure. Thanks for the contribution. This was a long standing issue with around 96 votes on uservoice. Great impact 🎉

singhsarab pushed a commit to singhsarab/testfx that referenced this pull request Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants