Questions tagged [mstest]
Microsoft .NET Unit Testing Framework (MSTest)
3,272
questions
0
votes
1
answer
51
views
How to implement custom [Ignore] attribute for unit tests? (Skip some tests in RELEASE configuration)
I'm using MSTEST. I wish to tag test methods with the [TestWithCheats] attribute. These tests should be skipped without failing if they are run in the RELEASE configuration. However, they must be ...
1
vote
1
answer
63
views
How to show Console.WriteLine's message in VsCode Testing in C#
I have a MSTest project in my solution like this:
[TestClass]
public class Tests{
[TestMethod]
public void Test1(){
var result = "Hello 1";
Console.WriteLine(result);
...
-1
votes
0
answers
58
views
Azure Devops - Run automated test from test plan
I’m trying to run automated test in devops azure using mstest by running the tests from test plan
I have a .net project using mstest to run some tests. I create a pipeline that works and I want to ...
0
votes
0
answers
47
views
How to run different test classes in different assembly sequentially by Azure pipeline and MsTest?
We are using azure pipeline to run our unit tests, the yml file is like below:
But there are two test cases in two separate dlls which overlaps each other and cause race condition, say Test1 in ...
0
votes
1
answer
15
views
Intermittent problem using TestContext.AddResultFile (MSTest || TFS)
I'm using TestContext.AddResultFile to add logs to the attachments tab. The same code is used in every test case, but sometimes the test logs don't appear in the attachments tab. This inconsistency ...
1
vote
1
answer
42
views
How to mock a task from a dependency called from an external consumer
I'm a newbie in mocking and was asked to build some unit tests for a method, what I understood so far is that one dependency of this class (where the method to be tested is located) waits for a ...
0
votes
1
answer
21
views
C# MsTest with WinUI 3 in .Net 6.0 gives error "Processing Resources failed with error: Duplicate Entry"
I am building a WinUI 3 app in C#, .Net 6.0, VS 2022 and I would like to add Unit Tests using MsTest but I get errors when I try to reference back to the project that I want to test. Is it possible to ...
0
votes
1
answer
39
views
Is it possible to see the order in which tests are run in visual studio?
I have a suite of 800-odd tests in a C# solution. They are using XUnit. The xunit.runner.json demands that the tests be run serially. In other words, there should never be more than one test running ...
1
vote
1
answer
19
views
MS Test unit tests run in dotnet test but fail in VS 2022 test explorer when Mozilla VPN is active
When Mozilla VPN is active, the VS test explorer fails to find the test host and times out after 90 seconds, when the VPN is not active, the tests run fine. The VPN does not affect test runs via ...
0
votes
1
answer
29
views
How to mock a Sequence with a GUID Parameter using moq C#
I have the following concrete code:
var allBookedPos = await _dataService.GetAllBookingsForVendorInAwitingApproval(purchaseOrder.VendorCode);
foreach (var booking in allBookedPos)
{
// get ...
2
votes
0
answers
57
views
Mocking Filtered Data in C# with MSTest
I'm new to C#, I'm attempting to mock filtered data in C# unit tests using MSTest for a service that retrieves student data from a database. The code below successfully mocks the entire student data ...
2
votes
1
answer
46
views
DynamicData not working as expected when using an ImmutableList
Consider the following code:
public static IEnumerable<object[]> TestData
{
get
{
yield return new object[]
{
"hello",
ImmutableList<...
1
vote
1
answer
29
views
Setting lambdas for KeyVaultSecret on ReturnsAsync
I'm using Moq 4.18.4 and I'm having trouble when setting the ReturnsAsync, it is showing to me the following error
ISetup<SecretClient, Task<Response>>' does not contain a definition for '...
1
vote
0
answers
26
views
VS/C# Unit tests for SFTP Client // Mocking an SFTP Server
I'm trying to figure out how to create a unit test for code that generates and uploads text files to an SFTP server.
I've tried running a local SFTP server for the unit tests to access, but it's messy ...
0
votes
0
answers
33
views
C#.net OpenFileDialog SaveFileDialog Test [duplicate]
I have the following code that I am struggling to test. How can I go about mocking these to test? I am using MSTest
public bool SaveToFile(string content)
{
using (SaveFileDialog saveFileDialog = ...
0
votes
0
answers
20
views
is there a way to parse sql files before they are executed in dbup using octopus deploy?
I use DbUp to deploy scripts. this is a part of a workflow that uses Octopus Deploy. we want to check if the scripts are valid before they are executed on a database. is there a way to do some sort of ...
0
votes
1
answer
77
views
Yaml strategy ignores MSTest Class Parallelization
We have MSTest Framework with set up parallelization in Class Level. Meaning, tests within classes are running sequentially. Tests from different classes can be run in parallel.
[assembly: Parallelize(...
1
vote
2
answers
95
views
c# variables with unit testing
I am new to unit testing, so I am trying out a few basic programs to test it with. If I have created a class with a private variable and declared two functions, is there a way that the second ...
0
votes
1
answer
78
views
how to resolve no test matches the given testcase filter azure pipeline?
Those unit test are executing in azure pipeline before swap. After executing everytime it's showing me this.
/TestAdapterPath:"F:\agents04_agent04\r2\a"
2023-10-12T20:10:01.1725408Z Starting ...
0
votes
0
answers
24
views
Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables
I am trying to create and execute Shims from MS unit testcases in Visual Studio 2019. But, getting following error. How to resolve the following error. Thanks in advance.
Errror:
Microsoft....
0
votes
0
answers
29
views
Using stored procedure in MSTest DataSource (C#)
Is there any way that a MSTest unit test can call a stored procedure in its DataSource attribute instead of just referencing a table in the connection string?
TIA
0
votes
1
answer
67
views
how to write unit test case for ternary condition using MSTest C# .Net 6
public static Transaction Update(Transaction authData, CreateArguments arguments)
{
if (authData == null) return null;
**authData.CampaignId = string.IsNullOrWhiteSpace(arguments.CampaignId) ?...
-1
votes
1
answer
55
views
Adding list of records Failed in Entity Framework
I tried to add entities to the database with Entity Framework, but it failed. Here is the source code that is responsible for adding a list of entities to the database:
public class ...
0
votes
0
answers
45
views
How to run each feature file with scenarios on different chrome instances parallelly?
The Problem:
I am using MSTest framework for running UI tests. I have 10 feature files each having at least 20 scenarios. I am able to run them successfully using a pipeline, but it takes around 4-5 ...
0
votes
0
answers
36
views
How do I create an MSTest project in a .NET console application
How can I insert a MSTest project in a .NET C# console project. My idea was to create a console project as a solution and create a mstest project in it.
My directory structure looks like this.
...
1
vote
1
answer
26
views
How to create and pass IConfiguration using MSTest
I have a concrete service that is declared in the form:
public class ApiDataService:IApiDataService
{
private IConfiguration configuration;
public ApiDataService(IConfiguration _configuration)
...
-1
votes
1
answer
78
views
If I need to check the parameter of the function?
I'm writing unit test using MSTest in C#.
The end goal of function is to ensure we can get the data.
The function we want to test is like:
public static GetMemberName(string member_id)
{
DataTable ...
1
vote
1
answer
194
views
Microsoft Fakes Shims in .Net 6.0
I m trying to enable shims in my testing via Microsoft Fakes by following this article:
https://learn.microsoft.com/en-us/visualstudio/test/using-shims-to-isolate-your-application-from-other-...
1
vote
1
answer
107
views
TestExplorer missing single test data entries when using DynamicData with complex types
When I use the [DynamicData] attribute to provide an enumeration of primitve values, e.g. int, then the Visual Studio Test Explorer shows one test for each value provided via dynamic data:
public ...
1
vote
2
answers
68
views
Unit Test throws TargetParameterCountException when using params array
I'm setting up unit tests using Microsoft.VisualStudio.TestTools.UnitTesting test attributes. I'm trying to pass a different number of elements into a params array in my test method, as described in ...
1
vote
2
answers
164
views
Running MSTest unit tests in Visual Studio 2022
Visual Studio 2022 17.6.2
EDIT: The relevant solution is entirely Desktop. WPF, console, and class library projects are included, but Internet and Web capabilities are not relevant.
I have several ...
0
votes
0
answers
58
views
Tests from non-public classes silently ignored
I am using Mstest v2 and run my test from within Visual Studio. If a test class is marked with [TestClass] but only internal, its tests are not found/ignored.
How to get a warning or even better error ...
2
votes
2
answers
244
views
How do I convert xUnit/dotnet test output to annotations in GitHub actions using a problem matcher?
I have a GitHub action that runs .NET xUnit tests using dotnet test:
jobs:
build-net:
name: .NET build & test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name:...
2
votes
2
answers
66
views
Unit testing a overridden protected method from a class that does not have default constructors
I have a class like this: Notice it does not have a default constructor either and inherits from some other class
public class IdentifierManager : IdentifierManagerBase
{
public IdentifierManager(...
0
votes
0
answers
107
views
How to resolve: "Could not load type 'System.Windows.Threading.DispatcherTimer' from assembly 'WindowsBase, Version=4.0.0.0"?
I'm unit testing a WPF project whose target Framework is.NET Framework 4.7.2.
I created a MSTest test project whose target Framework is .NET 7.0.
Here is a class in the WPF project I try to unit test. ...
1
vote
1
answer
76
views
MS Test giving inconsistent results for simple tests
The following tests are detected differently by the Visual Studio Test Explorer and have different output formats despite their similarities.
[TestClass]
public class UnitTest1
{
[TestMethod("...
4
votes
3
answers
87
views
Why does checking if a Type of System.Int32 is assignable to Type of INumber<> return false in a unit test?
This statement when run from a console application sets 'x' to true:
var x = 3.GetType().IsAssignableTo(typeof(INumber<>)); // x == true
The same statement when run inside a unit test sets x to ...
0
votes
1
answer
115
views
Coverlet does not generate cobertura.xml for MSTest test projects
I have a solution with multiple test projects (MSTest). I wanna check my code coverage for the entire solution. To do this, I type the following command:
dotnet test --collect:"XPlat Code ...
2
votes
2
answers
51
views
How to unit test the setters with OnPropertyChanged(); in it?
I'm testing a view model with getters and setters(). it's base class is ObservableObject and has OnPropertyChanged() in setter. I don't know how to test the setter to verify the value is set and ...
0
votes
0
answers
33
views
Struct Layout with array disables tests
Creating a packed struct in C# that contains an array causes all tests in my test project to produce an inconclusive result. In the case of Resharper's test runner, it produces the exit code 14942211. ...
0
votes
1
answer
84
views
MSTest Project targeting .NET is not available from the project template
In Visual Studio 2022 Enterprise I don't see Unit Test Project for .NET (eg. .Net Core) in the project template. Specifically, I am looking to create MSTest projects targeting .NET 6 but all I see is ...
1
vote
3
answers
63
views
How to compare the current URL?
I want to assert the URLof the page after login. This is my method so far:
public bool UrlEqualsBookingPage()
{
string currentURL = Client.GetCurrentUrl();
string expectedURL = "https://...
0
votes
0
answers
93
views
Failed to load assembly Microsoft.VisualStudio.TestPlatform.Fakes
I am using Visual Studio 2022 (Professional). When I am trying to run MSTests for C# project I got this message in log.
Failed to load assembly Microsoft.VisualStudio.TestPlatform.Fakes
Project use ....
0
votes
1
answer
88
views
How can I choose .NET Framework when create a NUnit Test Project with Visual Studio 2022?
In Visual Studio 2022, I can not find the .Net Framework option when creating a NUnit Test Project.
All options here
Please help me if there is any idea. Thank you.
I have tried with another computer ...
1
vote
0
answers
79
views
C# MSTest "No test is available" via gitlab runner
I'm trying to setup some GitLab CI for C# .NET Framework 4.8 (windows) including MSTest project.
Using a windows runner locally on my workstation referencing msbuild and vstest.console within Visual ...
0
votes
1
answer
51
views
How to assert that a specific request header is sent in a outgoing request C#
I want to test a scenario
As part of the API logic a header will be sent as part of an outgoing http call.
like
public class MyClass{
public NewResponse MySepcificHeaderApi(...
0
votes
1
answer
146
views
Unit testing blazor component that includes StateHasChanged() method with MSTest
While writing a unit test for a blazor component which renders a TreeView from Telerik, I stumbled upon this error:
Message:
Test method Redacted.Web.Client.UnitTests.Components.TreeViewTest....
0
votes
0
answers
8
views
How to show the current execution progress of the Test Method on command line (MSTest Project )
I have developed an MS Test project for writing unit tests. In a test method which runs for long time, I want to print the current status to the standard output. I tried Console.Writeline(), ...
1
vote
1
answer
135
views
Why does a test method with DataTestMethod decorator fail to run more than once when multiple DataRows with array arguments are specified?
I discovered surprising behaviour of the DataTestMethod and DataRow attributes. I have implemented the following test; of course the overall context is more complex, but this is a minimal example.
[...
0
votes
1
answer
192
views
I get a System.ArgumentException when running MSTest tests for a console app that contains a Main method without args
I have a basic console application developed in C# 10, which is designed for .NET 6.0. The app receives the complete file path as input, verifies its existence, and logs a message to the console ...