microsoft / testfx

MSTest framework and adapter
MIT License
716 stars 253 forks source link

Can run tests locally but not on TFS Test Agent: Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext. #207

Closed curtishx2 closed 6 years ago

curtishx2 commented 7 years ago

Description

I'm trying to get a unit test project to run on a TFS Test Agent. One of the test classes has a ClassInitialize function like so:

[ClassInitialize] public static void Initialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext tc)

but I'm getting the following error on the TFS Test Agent:

Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.

I did see this other issue. My problem is similar, but different enough.

The unit test project used to have a .testsettings file, but was removed. It references version 1.1.18 of MSTest V2. I can build and run the tests locally, but they will not run on the test agent. I think the Microsoft.VisualStudio.TestPlatfor.TestFramework DLLs are getting copied down, but can't be sure because the test controller deletes the deployed files after every test run.

I can run the tests locally on my development machine, but they will not run on the test agent.

AbhitejJohn commented 7 years ago

@curtishx2 : What version of the agent SKU are you on? This looks like it isn't using MSTest.TestAdapter to run your tests. I hope you chose vstest.console.exe as the runner. In that case turning on diagnostic logs on the agent machine can help find out what's happening.

AbhitejJohn commented 7 years ago

@curtishx2 : pinging back on this. Feel free to close if this is resolved at your end.

curtishx2 commented 7 years ago

I never did get it to work with the [ClassInitialize] attribute. I moved the initialization code into the [TestInitialize] method. Sure, the initialization code only needed to run once per test run, but having the initialization code run on every test was the only way to get it to work, and I don't have the time to look into the issue.

jpenniman commented 6 years ago

We have the exact problem. Runs locally, but not on the HOSTED 2017 agent in VSTS.

We're using the latest nuget packages for MsTest. The test project and project being tested are net461.

We had to provide a custom path and reference vstest.console.exe directly (similar to the workaround for core) to even get this far. If we tell the task to use Visual Studio 2017, it doesn't discover any tests.

Our vsts log...

2017-12-08T16:50:15.8144414Z ##[section]Starting: Run Integration Tests
2017-12-08T16:50:15.8350210Z ==============================================================================
2017-12-08T16:50:15.8350423Z Task         : Visual Studio Test
2017-12-08T16:50:15.8350529Z Description  : Run tests with Visual Studio test runner
2017-12-08T16:50:15.8350631Z Version      : 2.2.10
2017-12-08T16:50:15.8350745Z Author       : Microsoft Corporation
2017-12-08T16:50:15.8350856Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2017-12-08T16:50:15.8350971Z ==============================================================================
2017-12-08T16:50:19.5576858Z Run the tests locally using vstest.console.exe
2017-12-08T16:50:19.5577052Z ========================================================
2017-12-08T16:50:19.5577300Z Test selector : Test assemblies
2017-12-08T16:50:19.5577478Z Test assemblies : **\Release\Database.IntegrationTests.dll,!**\obj\**
2017-12-08T16:50:19.5577672Z Test filter criteria : null
2017-12-08T16:50:19.5577825Z Search folder : d:\a\r1\a
2017-12-08T16:50:19.5578024Z Run settings file : d:\a\r1\a\SnapChef\drop\Database.IntegrationTests\bin\Release\Database.IntegrationTests.testsettings
2017-12-08T16:50:19.5578563Z Run in parallel : false
2017-12-08T16:50:19.5578701Z Run in isolation : false
2017-12-08T16:50:19.5579462Z Path to custom adapters : null
2017-12-08T16:50:19.5579599Z Other console options : null
2017-12-08T16:50:19.5579735Z Code coverage enabled : false
2017-12-08T16:50:19.5580100Z vstest.console.exe, specified location : C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform
2017-12-08T16:50:19.7364367Z ========================================================
2017-12-08T16:50:19.9146979Z ##[warning]Properties specified in testsettings file can be accessed via the TestContext using Visual Studio 2017 Update 4 or higher
2017-12-08T16:50:19.9166648Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" d:\a\r1\a\SnapChef\drop\Database.IntegrationTests\bin\Release\Database.IntegrationTests.dll /Settings:d:\a\_temp\dfb96270-dc37-11e7-980f-c5d100132ed5.testsettings /logger:trx "/TestAdapterPath:\"d:\a\r1\a\""
2017-12-08T16:50:19.9170035Z Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
2017-12-08T16:50:19.9170153Z Copyright (c) Microsoft Corporation.  All rights reserved.
2017-12-08T16:50:19.9170327Z 
2017-12-08T16:50:19.9814230Z Starting test execution, please wait...
2017-12-08T16:50:22.1325174Z Warning : A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter.
2017-12-08T16:50:36.9198010Z Failed   Database.IntegrationTests.ViewTests.OrderFulFillment
2017-12-08T16:50:36.9219125Z Error Message:
2017-12-08T16:50:36.9220035Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9224107Z 
2017-12-08T16:50:36.9519450Z Failed   Database.IntegrationTests.ViewTests.OrderHeader
2017-12-08T16:50:36.9520544Z Error Message:
2017-12-08T16:50:36.9521286Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9521495Z 
2017-12-08T16:50:36.9524038Z Failed   Database.IntegrationTests.ViewTests.CustomerSummary
2017-12-08T16:50:36.9524940Z Error Message:
2017-12-08T16:50:36.9529532Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9529661Z 
2017-12-08T16:50:36.9529763Z Failed   Database.IntegrationTests.ViewTests.EmployeeSummary
2017-12-08T16:50:36.9529862Z Error Message:
2017-12-08T16:50:36.9531026Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9531187Z 
2017-12-08T16:50:36.9531289Z Failed   Database.IntegrationTests.ViewTests.OrderSummary
2017-12-08T16:50:36.9531400Z Error Message:
2017-12-08T16:50:36.9531548Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9531638Z 
2017-12-08T16:50:36.9531736Z Failed   Database.IntegrationTests.ViewTests.FranchiseSummary
2017-12-08T16:50:36.9531833Z Error Message:
2017-12-08T16:50:36.9531984Z  Method Database.IntegrationTests.ViewTests.ClassInitialize has wrong signature.  Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
2017-12-08T16:50:36.9532072Z 
2017-12-08T16:50:36.9554859Z 
2017-12-08T16:50:36.9556019Z Total tests: 6. Passed: 0. Failed: 6. Skipped: 0.
2017-12-08T16:50:36.9563214Z Test Run Failed.
2017-12-08T16:50:36.9576155Z Test execution time: 15.7712 Seconds
2017-12-08T16:50:36.9881557Z Results File: d:\a\r1\a\TestResults\buildguest_factoryvm-az187_2017-12-08_16_50_36.trx
2017-12-08T16:50:38.8624402Z ##[warning]Vstest failed with error. Check logs for failures. There might be failed tests.
2017-12-08T16:50:39.0401082Z ##[error]Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe failed with return code: 1
2017-12-08T16:50:40.0327194Z ##[error]VsTest task failed.
jayaranigarg commented 6 years ago

@jpenniman :

2017-12-08T16:50:19.5578024Z Run settings file : d:\a\r1\a\SnapChef\drop\Database.IntegrationTests\bin\Release\Database.IntegrationTests.testsettings

It looks like you have the legacy .testsettings specified. If there isn't anything specific that you need in a testsettings, do remove it or move over to .runsettings.

Testsettings are not supported with MSTestV2 and it throws out the following warning when these settings are used: Warning : A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter.

jpenniman commented 6 years ago

Thanks @jayaranigarg, using a runSettings file instead worked. Now vsts doesn't actually use the runSettings file, but that's a different issue.

jayaranigarg commented 6 years ago

@jpenniman : Glad to hear that the issue got resolved..!! Please feel free to re-open the issue if you face it again.