Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Asynchronous test methods rejected unless they use the async keyword #500

Closed
spanglerco opened this issue Oct 11, 2018 · 4 comments
Closed

Comments

@spanglerco
Copy link
Contributor

Description

I have a test method that returns a Task. This works when the method also uses the async keyword, but removing the async keyword results in UTA007: Method does not have correct signature. This appears to be intentional based on the IsValidTestMethodShouldReturnFalseForMethodsWithNonVoidReturnType test, but I'm wondering why the caller should care if the method is implemented via async state machine or not.

If it's not intentional, I have a potential fix in my fork that I can create a PR for.

Steps to reproduce

[TestClass]
public class MyTests
{
    [TestMethod]
    public Task MyTest()
    {
        return Task.CompletedTask;
    }
}

Expected behavior

MyTests.MyTest is discovered as a test to run.

Actual behavior

UTA007: Method MyTest defined in class MyTests does not have correct signature. Test method marked with the [TestMethod] attribute must be non-static, public, return-type as void and should not take any parameter. Example: public void Test.Class1.Test(). Additionally, if you are using async-await in test method then return-type must be Task. Example: public async Task Test.Class1.Test2()

Environment

MSTest 1.3.2

@vagisha-nidhi
Copy link
Contributor

Thank you for your feedback.
We have looked into this and found that this behavior of MSTest is by design.

@mayankbansal018
Copy link
Contributor

mayankbansal018 commented Oct 26, 2018

@spanglerco , I see no specific reason for methods returning Task to be defined as asyn, if they are not doing any async work inside. Can you please raise PR for this.

/cc @jayaranigarg

@mayankbansal018
Copy link
Contributor

@AbhitejJohn any particular reason why we do not run methods which have return type Task, unless they are defined as async?

@AbhitejJohn
Copy link
Contributor

@mayankbansal018 : This is probably an artifact of the past. I do not see any reason why that should still be the case but please make sure that any documentation is updated as well.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants