Click here to Skip to main content
15,887,027 members
Everything / NUnit

NUnit

NUnit

Great Reads

by Sean Rand
Getting the most from your test runner
by Sem Shekhovtsov
The how-to article that summarises best practices for unit testing ASP NET Core MVC controller using NUnit and Moq framework
by Robert Gowland
Reduce duplicate code in your unit tests with NUnit's parameterized testing attributes. Learn how with this easy refactoring exercise.
by Sacha Barber
MsBuild and NUnit (a simple example)

Latest Articles

by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
by Dev Leader
Learn to create tests, use advanced techniques, and improve your code quality!
by Mohammed Faci
Get started with Playwright using VS 2022/C# and NUnit

All Articles

Sort by Updated

NUnit 

4 Apr 2024 by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
16 Feb 2024 by Dev Leader
Learn to create tests, use advanced techniques, and improve your code quality!
5 Feb 2024 by Mohammed Faci
Get started with Playwright using VS 2022/C# and NUnit
4 May 2023 by Jagadeeshds
Hi Guys, I tried to use NUnit test case in visual studio . Added bin file of Nunit ASP 2.0 . But, NUnit.Framework keyword not found. In Nunit 3.13.3 unable to find dll file. How to get NUNit.Framework feature using NUnit ASP 2.0. HELP...
4 May 2023 by Graeme_Grant
We can't see your screen from here. We're not here to do your work for you, but are happy to point you in the right direction. Here is the best place to start looking: how to use nunit with asp.net 2.0 | Google Search[^]
27 Oct 2022 by Virendra S from Bangalore, Karnataka
I am new to unit testing, please help me with writing correct unit tests for below method. Functionality: It just calls one method internally & get the object, based on object value returns true/ false. public bool...
27 Oct 2022 by Graeme_Grant
Google search is your friend. 1. NUnit: nunit bool check - Google Search[^] finds this: Assert.True | NUnit Docs[^] 2. XUnit: xunit bool check - Google Search[^] finds this: Xunit.Assert.Equal(bool, bool) Example[^] For XUnit, I like using: ...
11 Aug 2022 by Virendra S from Bangalore, Karnataka
public ProductConfigDetails GetProductConfig() { ProductConfigDetails ProdConfigDetails; if (appsettingsconfiguration.UseMockData) { taxConfigDetails =...
20 Oct 2020 by Oshtri Deka
In your case obj is instance of MyClass and value is list you wish to pass. var obj = new MyClass(); var newValue = new List(); fieldInfo.SetValue(obj, newValue ); Read more about it.
20 Oct 2020 by BishnuKarki
Here is my scenario. I have a MyClass class and protected field _myAttempt which is a list. _myAttempt list class looks like below. From MyClassTest, how can i assign value to Daily using Reflection. I have tried following under...
16 Jul 2020 by Smita Ast
Hi everyone, I need to fetch data from excel, like 5 items into list box, how can I do with single item able to pass.? JEERA PISTA BADAM Sugar etc.... What I have tried: Recipe.SelectIngredienttype(ExcelUtils.ReadData(1,...
16 Jul 2020 by Code Artist
If these data must be from Excel, try ClosedXML to read content from excel. Otherwise, consider to have it in text file where you can just read it as follow: string [] data = File.ReadAllLines();
13 Jun 2020 by Member 13187373
Hi All, I am using Windows form application. I have total 688 unit tests written in my project. When I am running these unit tests on my local development environment then these all are passing successfully but when I am running these unit tests...
15 Apr 2020 by Member 14779968
Currently I have configured Extent report for my test cases. I have several projects under my solution. I am generating the report in "Reports" folder that i created in each project. However I want to know How can I store this in one common...
20 Jun 2019 by F-ES Sitecore
That code can't be unit tested. What is it you're actually testing? File.Exists? File.Copy? Those are third-party functions, you should just assume that they work. To make that code testable you'll need to create some kind of IFileManagement service that has Exists and Copy methods on it. ...
20 Jun 2019 by MAN CHUN LIEW
The sourceFile will pass in the path of the file and in destination which is the copy funciton will copy the sourceFile to it. public bool CopyFile(string sourceFile, string destinationFile) { if (File.Exists(sourceFile)) { ...
19 Oct 2018 by Sean Rand
Getting the most from your test runner
25 Sep 2018 by Member 13996859
Here its my code: a = driver.Findelement(By.XPath("Element1"))); b = driver.Findelement(By.XPath("Element2"))); Thread.Sleep(3000); action.ClickAndHold(a).MoveToElement(b).Release().Perform(); This Drag and Drop Action performed well. But when other drag and drop action try to runs, The first...
6 Sep 2018 by Member 13715690
We have a NUnit project where I need to execute the code in parallel with different configuration for each instance. We will refer a config.json file which will have the path of some files and user credentials. As of now only one config.json file is fetched and it is executing sequentially. My...
13 Jun 2018 by Member 13871081
I am hoping I can get some insight to a issue I have been struggling to resolve. I am new to c# Nunit and Visual studio. I have an XML storing usernames and XML storing passwords and .resx file in Visual Studio storing all the browser names. Every password and username has to be parallel tested...
8 Apr 2018 by Sem Shekhovtsov
The how-to article that summarises best practices for unit testing ASP NET Core MVC controller using NUnit and Moq framework
9 Mar 2018 by Member 13715690
My requirement: I want to read multiple TestData for single case and execution with all TestData should happen by itself. TestCaseSource attribute provides these requirement but not exactly. Using TestDataSource it is fetching TestData of tests which need not to be executed.If 100 tests are...
8 Mar 2018 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which...
8 Mar 2018 by Member 13715690
I'm running from visual studio the case got passed. But while running the same from cmd prompt by using the dll file i'm facing this issue. // Get the test data in table format and store it in DataRow type. DataTable DTExcelresult = IO.ReadExcel( excelLocation, methodName );...
13 Dec 2017 by Leo Chapiro
The function you want to test need to be public: you can't access any private function out of class itself! Then take a look how to create a NUnit project; Unit Testing Using NUnit[^]
13 Dec 2017 by Mahesh Alappuzha
hi i have a public class inside this class i have a private function public class ClassName { private void SetBillingContactEmail() { //Return if billing contact and its emails are null if (_companyview.BillingContact == null ||...
15 Sep 2017 by Valerii Tereshchenko
The article presents idea and implementation of class to manage selection of only one element in different linear and hierarchical structures
29 Aug 2017 by Valerii Tereshchenko
Asynchronous validation for MVVM(WPF)
19 Jul 2017 by Alain Leglise
I'm using Visual Studio 2012 / C# with nUnit test, and get System.AccessViolationException on simple test... When I launch the "Execute Test" option, the test returns OK. When I launch the "Debug Test" option, I get System.AccessViolationException. I think something in my config is not good....
19 Jul 2017 by Satya Prakash Swain
It looks like this VS bug: Weird Access Violation Exception Reported here: https://connect.microsoft.com/VisualStudio/feedback/details/911564/access-violation-exception-in-vs-hosting-process-when-debugging-application And assumingly fixed in this .NET release:...
2 Jul 2017 by Anton Angelov
Learn how to create .NET Core projects that can run Selenium WebDriver tests. Execute from command line simultaneously MSTest, NUnit and XUnit tests
22 Jun 2017 by Viktoriano
New features overview of NUnit 3.7 version
22 Jun 2017 by Viktoriano
To provide a solution which helps to pass a necessary browser to Selenium WebDriver tests through the NUnit
24 Mar 2017 by Mehul M Thakkar
I want to call a wcf service from my Tests. The service is running in same network with different domain. So to call that I need different windows user account who has permission of that service.In my test case, I have used LogonUser API for impersonation. It is working fine to run tests...
7 Feb 2017 by pgshsf
Is there a way to do the following things using NUnit and TFS?1.Retrieving the test cases parameters from Team foundation server/service;2.Then map it to an interface or class;3.Executing the test methods based upon the test case parameters which are downloaded;4.Finally updating the...
6 Jan 2017 by Debendra0256
In this article we will see one of the most important unit testing framework in DotNet.
20 Nov 2016 by Sibeesh Passion
How to write unit test cases for our WCF Service with a framework called NUnit
22 Aug 2016 by VicQA
Hello Everyone,I am trying to run a batchfile that contains commands to hit a nunit console runner executable. I am using the system.diagnostics.process method to run the batch fileHere is the code: Path used in...
22 Aug 2016 by OriginalGriff
Why are you using two relative directory codes in an absolute folder specification?Try:Process.Start(@"C:\Users\Victor\workstride-automated-tests\DextapAutomation\SeleniumDemo\Batchfiles\RandomBatchFile.bat", "C-Sharp Console application");And see if that works.
13 May 2016 by DannyFreeman
Writing unit tests for a deep clone method
11 May 2016 by witnes
Examples of Mock usages
18 Mar 2016 by Robert Gowland
Reduce duplicate code in your unit tests with NUnit's parameterized testing attributes. Learn how with this easy refactoring exercise.
7 Mar 2016 by Akhil Mittal
In this article we’ll learn on how to write unit tests for WebAPI controllers i.e. REST’s actual endpoints.
1 Mar 2016 by Akhil Mittal
In this article we learn how to write unit tests for core business logic and primarily on basic CRUD operations.
28 Jan 2016 by Member 12294034
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1{ public class Program { static void Main(string[] args) { Console.WriteLine("enter a"); ...
28 Jan 2016 by Sergey Alexandrovich Kryukov
You can write NUnit test method(s) in exact same way as it is usually done with NUnit. The basic idea is to create a class(es) (or use existing class(es)) marked with the attribute [TestFixture] and create some test method(s) marked with the attribute [Test] and then use the utility to perform...
11 Jan 2016 by Leo Chapiro
NUnit 3.0 Test Adapter for Visual StudioThe NUnit 3.0 Test Adapter allows you to run NUnit 3.0 tests inside Visual Studio. This is a new adapter, based partly on the code of the original NUnit Test Adapter, but modified to work with NUnit 3.0.It is not possible to run NUnit 2.x tests...
11 Jan 2016 by Asutosha
Hi,I add Nuint using nuget package managerAdd class libriary and write test methodin visual studio 2010Now How I will able to run this test ?
2 Dec 2015 by George Jonsson
Why not address your question to the NUnit team?http://www.nunit.org/index.php?p=contactUs[^]There also seem to be a 3.0.1 release. Maybe problem you experience has been fixed.
30 Nov 2015 by Suparn B
Hi,I am using specflow for BDD for a POC project. I had installed the nuget packages for Specflow ,Specflow.NUnit, NUnitTestAdapter and NUnit (version 2.6). I seemed to be happy since i was getting the expected result.After a few days, I am working on a new project and i installed all...
23 Jul 2015 by saumil.sapariya
I am integrating my .net application with Spring. I have trouble with getting Object with having constructor object.My Object patterns are like:public class Bar { private Foo foo; public void setFoo(Foo foo) { this.foo = foo; } public String...
17 Jul 2015 by Anshoo Arora
You can also try ReportUnit, which also supports Gallio and MSTest: http://relevantcodes.com/reportunit-report-generator/This is a simple exe file that will convert your xml report into an HTML dashboards (samples): - Folder-level dashboard: ...
17 Jul 2015 by sencsk
Hello Team,Here i want to know how to execute the Test cases as my wish. because i need to change the order for run the Test. Example:testda1testmnd2testdsf3But Expectedtestda1 testdsf3testmnd2Please Help me to Fix this.
26 Jun 2015 by Member 11354558
Hi,I'm using SAPNcoconnector libraries to fetch the data from SAP server. I'm trying to create nUnit test cases for this.In the below example when I tried to access Repository property it is throwing exception because I've provide dummy SAP credentials and I've created dest object with...
25 Jun 2015 by Suvendu Shekhar Giri
There is solution available in StackOverflow[^].From Visual Studio command prompt run followingvstest.console.exe /logger:trx .\TestProject\bin\debug\YourUnitTestAssembly.dllFind detailed solution with explaination hereVisual Studio 2012 Unit Test Report[^]Hope, it helps :)
24 Jun 2015 by Member 11749138
How to output the nunit test results to trx file in visualstudio 2012
11 May 2015 by CHill60
You could have a look at NUnitForms[^] or change myMethod to take a flag to say whether or not to show the message e.g. public int myMethod(bool ShowMessage = true){ int retVal = 1; if (ShowMessage) retVal = (MessageBox.Show("Sure?", "Title", MessageBoxButtons.YesNo) ==...
11 May 2015 by Trung Tuyen Tran
I use NUnit to test unit and I have a method:class abc { private int a; public void myMethod() { if(MessageBox.Show("Sure?","Title", MessageBoxButtons.YesNo) == DialogResult.Yes) a = 1; else a = 0; ...
21 Apr 2015 by DlogDash
It appears that DataContractJsonSerializer uses different precision to NetDataContractSerializer for DateTime. Testing of serialise-deserialise failed for a DateTimeOffset property if used strict equality or testing to the nearest Tick.The following code snippet fixed the issue (_entity1 was...
13 Apr 2015 by valiant123
hi,i am getting this error when im running the Nunit testcases,Initialsetup [TestfixtureSetup]of the Nunit itself failed, and the message is as below,System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is...
8 Jan 2015 by Kranthi Kavuri
I'm writing test cases on ASP.Net page. All the controls are in content holder.When I write test caes for the controls, it's throwing following exception "Problems with DOCTYPE DTD: The remote server returned an error: (500) Internal Server Error. Your DOCTYPE is probably incorrect. If...
29 Dec 2014 by Suvendu Shekhar Giri
There are a no of good tutorials available on the internet.Check following...
29 Dec 2014 by Kranthi Kavuri
If anybody has notes on it, please share itThanks in advance.
5 Dec 2014 by Ibrahim ben Salah
ASP.NET MVC application are highly testable when controllers are considered plain classes, but then you lose the integration with model validation, filters, method selectors, etc.
17 Nov 2014 by Member 11052680
I have written a test class for my controller class using NUnit and Moq framework.My classes are following,public class ClientTypeControllerTest { ClientTypeController objClientTypeController;[SetUp]public void Initialize(){ _clientTypeServiceMock = new...
5 Nov 2014 by maheswaran_s_v
return communityChestCardArray[card].ToString() needs to be added in the actual method.
5 Nov 2014 by DecompileCodex
I am using the NUnit framework for unit testing.My question is that in NUnit I am getting the error "MolopolyGame.Testing._Card.TestConstructor:No arguments were provided"The method which i am testing returns a random item in an array.I have a method which i need to testpublic...
10 Jun 2014 by MehraManish
unit testing of the view is not recommended
10 Jun 2014 by Sampath Lokuge
Please read below article.May be the starting point for you.Good Luck :)ASP.NET MVC Unit Testing using NUnit in Visual Studio
9 Jun 2014 by R-a-v-i-k-u-m-a-r
Sample Codepublic ActionResult SubjectExpertsList() { UsersListViewModel model = new UsersListViewModel(); model.UsersList = _userService.UsersList(Convert.ToInt32(Session["organizationId"])); model.UsersList = model.UsersList.Where(u => u.RoleId...
30 May 2014 by User 10132546
Using ClassAssert to check property mappings between different object types
25 Mar 2014 by kalaiselvan.rajendran
Need NUnit Test Case for the below Function. For the saem function If I Built the Datatable Inside the Function Test Case succeeds. If its comes from DB Test case fails. public ActionResult GetCustomerInfo() { DataTable dtCustomerInfo = BL.rptCustomerInfo(); ...
24 Mar 2014 by Keith Barrow
There are solutions to do this for you: See here[^] for a discussion on these.
24 Mar 2014 by nixonanand
Dear Professionals, How to convert nunit xml report to html report automatically.Please give me a step by step explanation.i have been searching in lot of websites.Still i didnt get a proper procedures. Please help me am in big trouble. ...
13 Mar 2014 by nixonanand
Hi professionals, i have faced one small trouble.please help me to resolve my problem...how to click element with title attribute.here i below mentioned html code,Here i want select...
6 Mar 2014 by AndrewCharlz
try removing display:none after mouse hoverthis can the problem
6 Mar 2014 by nixonanand
Dear Frds, I have a big trouble with accessing html element. the element is created after mouseover. How do i access the element.If page load that element is like
3 Mar 2014 by Sacha Barber
MsBuild and NUnit (a simple example)
28 Nov 2013 by James Coleman
Leveraging Selenium and Image Magick to perform screenshot comparisons for UI regression testing.
25 Nov 2013 by JoCodes
Sampath has posted some great reads . Just wanted to add one more article to it. http://www.developerfusion.com/article/9375/tdd-in-practice-dealing-with-hardtotest-areas/[^]
25 Nov 2013 by Sampath Lokuge
Please follow below mentioned articles and after that try to do your task..NET TDD (Test Driven Development) by example - Part 1[^]Test Driven Development(TDD) in C#[^]I hope this will help to you.
25 Nov 2013 by nikhilsreeni
Test Driven Development means write a test First Then we write code to make the test pass.Question: i need a calculator to add two numbers,platform console application input two numbers print the correct answer so help me to make the correct test case ?
4 Oct 2013 by Rob Philpott
Try [TestFixtureSetUp] instead of [Setup].
3 Oct 2013 by sencsk
Hi I've multiple Test Methods. The [setup] method will call each and every test. So My Test App getting too slow. any ways to run setup in a single time nor how to resolve the slow process.
2 Oct 2013 by Rob Philpott
Ok, based on that - two things.Firstly, I suspect that you may be using NUnit test runner, so I think it will be looking in that thing's app.config for the connection string rather than you app. That'd explain why it works with Microsoft's approach.Other thing (maybe not...
2 Oct 2013 by Fredrik Bornander
What does the app.config that's used when running NUnit look like?This sounds very much like a case of missing configuration, try making sure the configuration you need exists in the app.config of the test project.Hope this helps,Fredrik
2 Oct 2013 by Simon_Whale
HiIm testing out some testing software well NUnit and TDD. while I can get TDD to work with no problem I am struggling to get NUnit working property.Below is a simplified version of the class that I am running the test on. public class buildings : RatingBase { public override...
16 Sep 2013 by aida1986
i use httpContextBase in almost of method that i want to do a test , and the result of almost querries contains more than 300 rows ,i can't do the test with simple Nunit test
16 Sep 2013 by Leena 206
just go ahead, Install N-unit.. and run your test cases .. no matter how big is your data, tool will be running behind your application meanwhile you can proceed with your work :)If u r Beginner with N unit[^]
16 Sep 2013 by aida1986
I want to test a big number of data input and ouput with Nunit but i haven't any idea if someone has an idea tell me pls , khnowig that my project is done with ASP.NET MVC 4, RAZOR , Linq to enties
11 Sep 2013 by aida1986
i'm working with Nunit not MS test and i want to have test class for this method
11 Sep 2013 by Leena 206
Suppose you are checking for same things and error occure then you can show custom message as - Assert.AreEqual(Object, Object,Message);refer this : For showing custom message[^]
11 Sep 2013 by sencsk
Hi in my test method i have lot of Assertions. if any condition will fail. the program will be terminated. My Need is If any exception Occur i need to set the custom exception Message. Anybody know How to Proceed..
10 Sep 2013 by Jameel VM
You can write Unittest with both database data and Mock data. If you want to create a mock layer i recommend you implement the Repository Pattern and Dependency Injection.The below example i have demonstrate a basic unit test with basic ASP.NET MVC Unitesting framework without using...
10 Sep 2013 by aida1986
Hi , I have this method :public static IEnumerable ListeSessionFrais(MpxFraisContext db, int siteID, int stval, string codeFrais) { var sessionfrais = (from D1 in db.H59_MpxSessionFrais where D1.CodeFrais == codeFrais ...
4 Aug 2013 by Fredrik Bornander
You wrap the calls to static methods on DirectoryInfo in a class of your own that implements an interface.Something like this; public interface IDirectoryManager { bool Exists(string path); DirectoryInfo Create(string path); void Move(String...
4 Aug 2013 by mitesh_a
Hi I have following method in my class and I want to write unit test for it using nunit and rhino mocks. My method moves all the folders from source path to destination path, I am new to NUnit and Rhinomocks and I dont know how to mock System.IO.Directory or System.IO.DirectoryInfo objects. I...
25 Jul 2013 by Neerajan Lamsal
Unit Testing using NUnit.