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

Support generic test method #4204

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Youssef1313
Copy link
Member

Fixes #2402

@Youssef1313 Youssef1313 changed the title Initial generic test method support investigations (unested) Support generic test method Dec 1, 2024
@nohwnd
Copy link
Member

nohwnd commented Dec 2, 2024

I admit I did not read the whole PR in detail, but have you checked the impact on test id generation and if all the different ways you can use generic methods will reflect correctly there so we continue working with test explorer?

The tests seem to be testing just data driven tests, but generic methods are also used as templates for tests where parent specifies the test, and children specialize the tests. e.g. This 1 set of tests works for all implementations of IRepository.

I don't say you should implement all that, but enabling generic methods in one place should probably at look at how much other work it will be to enable this in other places as well.

@Youssef1313
Copy link
Member Author

I admit I did not read the whole PR in detail, but have you checked the impact on test id generation and if all the different ways you can use generic methods will reflect correctly there so we continue working with test explorer?

I'll do quick testing for TE, then maybe we can sync to make sure everything is fine.


The tests seem to be testing just data driven tests, but generic methods are also used as templates for tests where parent specifies the test, and children specialize the tests. e.g. This 1 set of tests works for all implementations of IRepository.

I'm not following. Could you give an example of non-data-driven test that is generic?

@nohwnd
Copy link
Member

nohwnd commented Dec 2, 2024

https://learn.microsoft.com/en-us/visualstudio/test/unit-tests-for-generic-methods?view=vs-2022#test-method something like this. Minus the helper method that actually runs the tests.

@nohwnd
Copy link
Member

nohwnd commented Dec 2, 2024

maybe something like this:

public void BinaryProtocolMessageCanBeSerializedAndDeserialized<TMessage>() { var mess =  new T() ... }

[TestMethod]
public void BinaryProtocolMessageCanBeSerializedAndDeserialized<HandshakeMessage>() => 
 BinaryProtocolMessageCanBeSerializedAndDeserialized<HandshakeMessage>();

@nohwnd
Copy link
Member

nohwnd commented Dec 2, 2024

disregard my comments, I think my brain does not work today.

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.

[DataTestMethod] is not allowed to be a Generic method
3 participants