Questions tagged [nunit]
NUnit is an open source unit testing framework for .NET and Silverlight written in C#. It serves the same purpose as JUnit or TestNG does in the Java world, and is one of many in the xUnit family.
7,440
questions
0
votes
1
answer
9
views
How can I combine IApplyToTest with TestFixtureSource to get descendant tests?
I have a custom attribute:
[AttributeUsage(AttributeTargets.Class)]
sealed class MyAttribute : NUnitAttribute, IApplyToTest
{
// ...
public void ApplyToTest(Test test)
{
// I need ...
0
votes
0
answers
29
views
How to mock 'IsSuccessStatusCode' of HttpResponseMessage in C# [closed]
I have the following function for which I am trying to write unit test case:
public async Task<ActionResult<string>> GetHealthCheck()
{
var isApiSuccessStatusCode = false;
...
0
votes
0
answers
40
views
No connection could be made because the target machine actively refused it. (localhost:7128)
I created test case for my scenario. while I am debugging the test case, I am getting No connection made error. I looked for many solution .But still issue is not resolved. Port Number which is ...
0
votes
0
answers
42
views
Unit testing issue with RegisterClassMap in CSVHelper after upgrading CsvHelper from 15.0.5 to 30.0.1
After upgrading CsvHelper, in the unit testing I am getting the
'Can not instantiate proxy of class: CsvHelper.CsvContext.
Could not find a parameterless constructor. (Parameter 'constructorArguments')...
0
votes
0
answers
13
views
Extent report getting created for each and every test class for C# NUnit Framework. How to solve it?
I need one consolidated extent report for my C# Nunit Framework. Following are my classes and code and explanations:
Base Class: Has the extent report setup [Version - 5.0.1], NUnit [version - 3.14.0],...
0
votes
0
answers
64
views
Use fields Owner and Tag on Azure Pipelines test report
I'm using pytest-nunit to generate a test report in azure pipelines. and I noticed two fields (Owner and Tags) that I would like to use, but couldn't find any documentation.
Any idea on what azure ...
1
vote
1
answer
33
views
NUnit : How to prevent calling base class constructor or mocking base class constructor (ASP.NET MVC controller method testing with NUnit)
I am testing an ASP.NET MVC application with NUnit (on the .NET framework).
I am trying to test SomeController method which is inheriting from BaseController.
In BaseController, there is a ...
0
votes
0
answers
28
views
Mongo custom serializer fails when running several test fixtures in a row
I am using Nunit for unit testing a project that uses MongoDb. I need a custom serializer to serialize objects from my own namespaces. I have encapsulated this registration within a static function. I ...
0
votes
0
answers
16
views
How to properly set up mock Request.Form in ASP.Net Core
I'm trying to create an HttpContextAccessor mock class for use in my controller unit tests. I have this so far.
public class MockHttpContextAccessor
{
public Mock<IHttpContextAccessor> ...
0
votes
1
answer
111
views
How to write unit test case and Mock SmtpClient Send mail
I am writing unit test case for the below class Communication service. I have the below interface communicationservice .
I want to write the Nunit or unit test for the SendMail method which is present ...
0
votes
0
answers
24
views
RestSharp testing for a BadRequest - fail before Assertion
Im trying to learn ReshSharp, NUnit testing and the whole lot. Currently attempting to test for a BadRequest during API call when i send it invalid data:
[Test, Order(1)]
[TestCase("...
0
votes
1
answer
21
views
How to pass Spaces in Scenario name in Test Explorer using SpecFlow, NUnit, Gherkin
i am working on a simple test case using SpecFlow and Gherkin Feature file i want to name my Scenario with spaces in Test Explorer
my Scenario name in Feature file
Scenario: "Perform a Google ...
0
votes
0
answers
19
views
Allure-CSharp Automation NUnit Playwright
I'm trying to determine if there's a possibility to automate the execution of allure-csharp with playwright programmatically via a web api call or cron job outside of test explorer. Furthermore, I ...
-1
votes
0
answers
19
views
NUnit build failed on Mac with Rider but works via CLI
I'm trying to build a net6 test project with JetBrains Rider on a M2 Mac. The net6 SDK is installed and I can successfully build the project via cli with dotnet build
But with Rider it is not possible ...
0
votes
0
answers
51
views
Any possibility to read the list of nunit tests triggered for execution in OneTimeSetup method
I need to read the list of tests in OneTimeSetup method which are going to be executed. For example, I have a test class with 5 tests and I am going to run only two tests and when it comes to ...
0
votes
1
answer
54
views
How to inject a fake without disrupting the code being tested
the following is the original text of the book 《The Art of Unit Testing, Second Edition》: Extract an interface to allow replacing underlying implementation
In this technique, you need to break out ...
1
vote
1
answer
38
views
Tests no longer provide the handy links. "run test | debug test" since dev kit change
VS code used to detect my C# tests and place a run or debug test button above the test method within test class. I am not sure if this is a result of the new dev kit extension but it was working when ...
0
votes
0
answers
5
views
Build produces many <country>-folders
In Visual Studio '22 in a Test project with NUnit, the V.S. build produces 13 folders with
codes of countries like de, es, fr, it, zh-Hans etc.
Each folder has the same set of 6 dll's e.g.
Microsoft....
1
vote
2
answers
46
views
How to Assert that a specific Exception is not thrown in NUnit?
I'm using NUnit for testing and have a piece of code where I use JObject.Parse(json). I want to ensure that this code does not throw a JsonReaderException. Here is the assertion I've tried:
Assert....
0
votes
1
answer
18
views
How to run C# NUnit automation tests from bibucket.org repository using jenkins localhost instance?
I am trying to run the C# automation tests which are present in a repository which is located at the bitbucket.org (It is a remote repository). The project uses C# and NUnit framework. I totally got ...
0
votes
0
answers
41
views
Is it possible to run NUnit tests from my code directly?
I have a ton of tests across multiple test files and test fixtures, and I need them to run in a specific order (regardless of what test fixture or file they are in). Currently I have a list of ...
0
votes
1
answer
56
views
The middleware doesn't start automatically, and it doesn't write to Serilog
Here, I'm attaching the code inside the middleware:
namespace ...
{
public class MyMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
...
1
vote
1
answer
65
views
How can I run multiple test fixtures in parallel using Selenium/NUnit?
I have a bit of a problem. I am working on an automation project and I'm trying to execute a test on multiple browsers in parallel.
I have these 2 classes:
[TestFixture(typeof(ChromeDriver))]
[...
2
votes
2
answers
69
views
Why can I replace the underlying implementation after extracting the interface?
the following is the original text of the book 《The Art of Unit Testing, Second Edition》:
Extract an interface to allow replacing underlying implementation
In this technique, you need to break out ...
0
votes
1
answer
28
views
Issue with Trigger Auto-Increment in Quartz.NET during NUnit Tests
I'm working on a project that utilizes Quartz.NET for job scheduling. I've implemented some tests using NUnit.Framework to verify the proper functioning of my scheduler. However, I'm encountering an ...
0
votes
0
answers
43
views
How do I pass a value in a Cmdlet class in F#?
I wrote a PowerShell function in F# and I would like to run NUnit tests on the functions.
In C# I wrote these tests previously:
[Fact]
public void ConvertJWTTest()
{
//-- Arrange
var base64 = &...
1
vote
1
answer
58
views
Place appsettings.json for NUnit on agent to use in Azure DevOps pipeline
I am using an Azure DevOps pipeline to execute unit tests and deploy my Blazor Server application to an agent. I use the NUnit test framework and PostgreSQL as database. For the unit tests, I use a ...
0
votes
0
answers
35
views
Why does the readability of the program decrease the more we use setup?
Quoted from 《The Art of Unit Testing》, Second Edition, Page 34
But know that the more you use [SetUp], the less readable your tests will be,
because people will have to keep reading test code in two ...
0
votes
1
answer
45
views
No test is available when running tests in Docker
I created NUnit project through Visual Studio and trying to run it in Docker.
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
...
0
votes
1
answer
47
views
How to create a Unit Test to access Views in c#
Im new to create a Unit Tests for Service class. Im facing an issue in accessing views in my context.
I have a two contexts one for writing and one for reading.Below are the sample for the context ...
0
votes
1
answer
62
views
Is there a way I can use the Test Description in a conditional Statement in a selenium test in C#?
I'm creating tests for an ordering system; I've created tests in C# using Visual Studio 2022 for various pages around it, and now I am creating tests for the ordering part itself. I have a BasePage ...
1
vote
1
answer
55
views
Is there a way to run multiple test orders in one instance of web browser?
Currently here is how my code looks:
This is in NUnit C#
[FixtureLifeCycle(LifeCycle.SingleInstance)]
[TestFixture]
public class xxxxx: xxxxx
{
private xxxxx xxxxx;
[SetUp]
public void ...
0
votes
1
answer
53
views
NUnit - trying to create a common test but got The test case source could not be found
I've decided to make my tests for a feature common, so I could pass on to it different implementations of classes but keep tests equal.
Here's the common test class:
internal abstract class ...
0
votes
0
answers
36
views
Playwright w/ Specflow and NUnit: Parallel execution only on some tests
I want to run some tests on parallel and some tests not on parallel. When I use [assembly: Parallelizable(ParallelScope.Fixtures)], all of the tests are running on parallel even if I use [...
0
votes
1
answer
46
views
Visual Studios C# Nunit Test Explorer does not show individual test
(https://i.stack.imgur.com/jZB2o.png)
[My Test Explorer should have an option to collapse each test to individually see the pass/failed test. Is there an option/view on visual studio that allows me to ...
0
votes
1
answer
23
views
Nunit: global setup method for running every tests in assembly
In Nunit we have Setup method that runs before every test in a TestFixture class. And we have OneTimeSetup that runs before all tests in an assembly.
But what I want is an attribute that I specify ...
0
votes
0
answers
32
views
NUnit tests fail because : No connection string named 'someEntities' could be found in the application config file, although it exists
I have a solution with 2 projects. The primary project is the MVC web application. The second project in the solution is NUnit tests for the repositories and the controllers in the MVC project. I ...
2
votes
1
answer
187
views
Why aren't my tests running in the expected order?
I have 1 test that runs significantly longer than others so I want that to start running first so others can be run in parallel with it.
The test in the derived class is using Order(1), as is the ...
0
votes
0
answers
19
views
Vstest task in Azure DevOps detecting non impacted test cases.?
We are planning to use the vstest task in our pipeline to only execute impact based nunit test.
we found that when we made a change in addition.cs file , the respective test cases are detected but ...
-1
votes
2
answers
53
views
Moq not running correctly and always gives wrong result
I created a small test project in VS 2022 -> .Net framework 4.7.2 to check the usage of moq.
Interface and the implementation are provided below.
public interface IDataMaintainer
{
bool AddData(...
0
votes
1
answer
52
views
Nunit testing for different environment variable values
I have a nunit test project. I want to cover the condition which is based on environment values , i have written tests for that which runs pefectly when i run them individually, but it fails when I ...
0
votes
0
answers
14
views
How to skip one testcase due to failure of another test case in nunit? [duplicate]
I have two methods.
Method1
Method2
If Method1 failes, I want to skip Execution of Method2. How to do that?
(In testNG we achieve this like =>> "@Test(dependsOnMethods = "Method1")...
0
votes
0
answers
53
views
Hooks : BeforeTestRun and AfterTestRun are NOT running when running specflow tests
Created a Feature File
Added a Scenario with Given, When, Then
Created a Hook File and added all hooks like [BeforeTestRun], [BeforeScenario], [BeforeStep] etc..
Inside each hook method I have added a ...
0
votes
0
answers
22
views
Webdriver reference is getting mixed with each other in parallel execution when we used ThreadLocal in Selenium C# with Nunit
Created a ThreadLocal instance with type of IWebDriver,
Base class we have extended in all test classes and driver.value is pass to all page classes while creating instance of page class in test ...
0
votes
1
answer
11
views
What sets, and how to control the "id" attribute in an NUnit result file "test-run" element?
I see that the first element in an NUnit testresult.xml file is "test-run", and it has an "id" attribute, such as the following example:
<?xml version="1.0" encoding=&...
0
votes
1
answer
28
views
Can't use Excel datasource in specflow, it is not working
My specflow with excel not working .I used the code like below:
Feature: Calculator

Simple calculator for adding **two** ...
2
votes
1
answer
25
views
How does NUnit run a list of test files?
I have a list of .dll files. How to run them in NUnit?
I remember in Python files can be run like this
suite = unittest.TestLoader().discover("./","*.py")
runner = unittest....
-3
votes
3
answers
58
views
How to write unit test for C# if else
I'm new to unit testing, I want to know that how we can write unit test for if else.
Public Shared Function PrependIconForNonApprovedMessage(message As String, Optional title As String = "") ...
-1
votes
1
answer
64
views
C# HttpClient request to invalid address returns "OK" 200 code. Why?
I have a weird problem. Im trying to write very simple c# nunit-based http request tests.
But when Im sending GET requests to non-existing endpoints I still get 200 "OK" code? Requests sent ...
0
votes
0
answers
30
views
C# .NET: Validator.TryValidateObject - Returns false in unit test but true in library
I have a class with a property that is all decorated up:
public class AClass
{
[DisplayName("A Property")]
[Phone]
[MinLength(10)]
[MaxLength(10)]
[RegexStringValidator(&...