Click here to Skip to main content
15,867,141 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 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
by Sean Rand
Getting the most from your test runner

All Articles

Sort by Score

NUnit 

19 Oct 2018 by Sean Rand
Getting the most from your test runner
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 Jan 2012 by CDP1802
This is very unusual. Unit tests are supposed to run automatically. They cannot do that while waiting for any kind of input.
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.
3 Mar 2014 by Sacha Barber
MsBuild and NUnit (a simple example)
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 :)
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
16 Mar 2011 by fjdiewornncalwe
Have you read this MSDN Tutorial? The concepts apply quite easily across to NUnit as the syntax is only minimally different. The Lessons Learned section in that article may be of benefit to you.
18 Mar 2011 by Eduard Keilholz
Erhm, are you sure your firewall is switched off, or that you've created a rule in your firewall allowing communication over the given port 61137?
21 Jun 2011 by Monjurul Habib
http://weblogs.asp.net/atlaszhu/archive/2009/05/05/webrequest-some-site-url-meeting-the-remote-server-returned-an-error-403.aspx[^]
6 Oct 2011 by sujanir
Hi,I have a data layer which returns List where "User" is a class object. What is the correct way to write Nunit test method for this. I am new to Nunit, I attempted to write using Assert calls. This looks insufficient. Iam unsure how I have to handle Nunit here. Any help...
20 Dec 2011 by Abhinav S
Try outhttp://msmvps.com/blogs/kevinmcneish/archive/2010/04/21/using-nunit-in-visual-studio-2010.aspx[^]http://www.damirscorner.com/UnitTestingWithNUnitInVisualC2010Express.aspx[^]http://vincenthomedev.wordpress.com/2009/06/18/running-nunit-2-5-against-visual-studio-2010-net-4-code/[^]
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 ?
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...
22 Jun 2017 by Viktoriano
New features overview of NUnit 3.7 version
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:...
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[^]
1 Mar 2011 by Ramalinga Koushik
Easy Debugging of NUnit Tests from Visual Studio 2008 Professional[^]article from CP might help you.
2 Mar 2011 by nguyen the trung
Dear all,I find out the problem, it may helps someone who is getting this trouble too.I have create unit test code with vs2008 automatically, so it uses [TestClass()] and [TestMethod()] to declare with vs 2008 while NUnit uses [TestFixture] and [Test].That's why NUnit did not...
18 Mar 2011 by Member 4545580
Hi Eduard,Thanks for your response.Port number is changing all the time. Now it's 61137 and last time it was some thing else.I am executing the DLL manually using NUnit in a single box..should I be checking the firewall even if the DLL is not calling any external...
22 Apr 2011 by snkscore
I don't know if this is possible, but I got this same error from NUnit when I actually had an infinite loop going in one of my tests.I had some overloaded assert method that ended up looping back on itself. When I ran the code using the TestDriven.Net tool I saw the stack overflow exception...
26 Apr 2011 by valiant123
Hi all,I am into the Interface project.I want to know whether I can do the nunit test for the services.Below is the short description about the project.Short Description:Data should be passed from one product to another and it must be synchronzied.We are using the APIs for...
9 Jun 2011 by Abhinav S
Read this[^]. It helps understand the difference between a mock and a stub.
21 Jun 2011 by Raj Bose
Hi all,In my NUnit project i am downloading videos from a other site then updating and uploading to my server.after 6 Insert and upload its gives me errorSystem.Net.WebException : The remote server returned an error: (403) ForbiddenPlease suggest what to do ?
21 Jun 2011 by fjdiewornncalwe
You should make sure that your access to the remote server is allowed. Forbidden usually indicates that the server's security profile has blocked you. Perhaps there is a limit as to how much you can download from that site in a given period of time.
23 Jun 2011 by Michael J. Eber
try this:public void ButtonClick1(object sender, System.EventArgs e){ ProcessStartInfo proc1 = new ProcessStartInfo(@"C:\\selenium-remote-control1.0.3\\selenium-dotnet-client-driver-1.0.1\\source\\tools\\nunit\\nunit-gui", "TestProject14.dll"); ...
6 Oct 2011 by Vivek Krishnamurthy
There are different ways you can perform unit testing of DAL.Option 1: In-memory databaseUsing an in-memory database and for testing run all the tests agains it. It is best if you can choose an in-memory database with which offers almost similar syntax as the actual database you are...
6 Oct 2011 by Mehdi Gholam
There is no correct way of writing test and most of the time efficiency is of no concern as the tool is doing all the work.You must note that writing great tests is not the goal, but the goal is writing great software so the test are only there to support the main code.Principals to...
29 Nov 2011 by Sergey Alexandrovich Kryukov
It sounds like you goal is to pass the test. You goal is just the opposite: to fail the test and figure out what's wrong in the code, get understanding of it. :-)Now, please see my comment to the question. Is it clear? Don't bother to supply missing information. Instead, just run the test...
20 Dec 2011 by Member 8412182
How to apply NUnit in VS 2010.
20 Dec 2011 by Suresh Suthar
Hope these links will help you..LMGTFY[^].http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/[^]http://greenicicleblog.com/2010/02/14/free-nunit-integration-for-visual-studio/[^]
8 Jan 2012 by Himanshu Bajpai
I am new in Nunit framework. So Please some one tell how to take input string through keyboard using NUNIT with c#.
24 Feb 2012 by jim lahey
Hello everyone,I'm seeing some strange behaviour in NHibernate, in particular that ISession.Refresh doesn't always do what it says on the tin when I call it. My code:public TEntity Refresh(TEntity entity){ Contract.Requires(entity != null, "entity"); ...
4 May 2012 by valiant123
Hi i am new to nunit. from the docs i understand we can do the testing when the method returns some values.then how can i Test the void methods using nunit.the methods does the connectivity functionality.do i need to use stubs or mock objects can be used.pls do help me with simple...
4 May 2012 by pietvredeveld
using (MockRepository.Record()){ mockedObject.Expect(mock=>mock.VoidMethod(expectedParameterIfAny));}using(MockRepository.PlayBack()){ objectToTest->SomeMethod();}
23 May 2012 by MD Niyaz Hashmi
How to debug nunit test cases in Visual studio 2010 Express edition?
23 May 2012 by Sandeep Mewara
Here: Debugging NUnit Tests in C# Express[^]
24 Jul 2012 by jayftee@gmail.com
Extract from Clean Coders StyleCop RulesYour cast seems bad. You are looking at a syntax similar to this:this.StyleCopConsole.ViolationEncountered += (sender, args) => this.StyleCopViolations.Add(args.Violation);namespace CleanCodersStyleCopRules.Test{ using System; ...
14 Sep 2012 by Linnet Robert
In my application I have some button click events and some functions. for this i need to write Nunit test. I wrote test for function but i don't know how to write test case for the button click events. please help me.Thanks in Advance
7 Oct 2012 by valiant123
hi folks,i need to write nunit test cases for the methods inside the private classi tried this way, but it doesnt work for me....[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ATests")]...is there is any other way to do write nunit test cases?
7 Oct 2012 by Nikhil_S
Here's The Link for NUnit TestCase Generator NUnit Test Case Code Generator[^]
12 Nov 2012 by PhrankBooth
I'm trying to run NUNIT tests through Reflection in C#. I load the assemble and get the methods, then I want to filter out for methods only assigned the NUnit.FrameWork.TestAttribute.I have tried this and it doesn't work: var testTypes = from t in ltAssm.GetTypes() ...
28 Nov 2012 by Giuseppe Tollini
Hi,I'm new to testingFor example I have a test (test1) that test if getFoo() return something and i have a more complex test (test2) that use one or more time getFoo()I want the test2 to not start if test1 fails or at least to fail automatically without start testing.I searched the...
26 Nov 2012 by Member 7850351
First of all...its a bad practice to call a test method in another test method.There should not be any dependencies among the test methodsThose should be able to execute independently.If you want to do it, probably one has to put check before Assert
25 Jan 2013 by Anmerin
hai. I am doing unit test on a method "Fetch" which is an IList,i want to display the count in nunit frame work if the test passes or fails.Here am using Console.writeline method.Is there any other method for my requirement. [TestCase] public void FetchTest() { ...
25 Jan 2013 by micke.andersson
You could try MessageBox.Show("count " + countToString());
30 Jan 2013 by VishwaKL
Hi Guys,I am new to NUnit testing, I want to write unit test case using NUnit,I have 4 layer architecture,UIEntitiesBODAOI want to pass Parameter fom UI to NUnit test project as Visual Studio support for Testing. i am not getting the solution please help me
30 Jan 2013 by Sandesh M Patil
Refer below linkhttp://stackoverflow.com/questions/5562184/how-to-pass-parameters-to-nunit-test-cases-through-the-ui[^]
29 Apr 2013 by Sergey Alexandrovich Kryukov
Please look here: http://nunit.org/index.php?p=parameterizedTests&r=2.5[^].—SA
1 May 2013 by valiant123
Hi folks,i am trying to write nunit for the methods which uses WMI.and i am not succeded in that. and now im doubting whether nunit can be done for methods which uses WMI.if it is possible kindly give me some sample code.
1 May 2013 by Abhinav S
You need not really write NUnint for WMI.These functions can be mocked[^] and you can assume is that either WMI will give you correct results or they will give you incorrect results.You can then write test cases for these two result types.Instead of Moles you can use other third...
9 May 2013 by ashok yede201
I wanna to write test cases in NUnit test project for REstful WCF service.How can I use NUnit test to test RestFul wcf services?Thanks in advance....
9 May 2013 by tumbledDown2earth
you can use the HTTPWebRequest/HttpWebResponse classes to make the requests/decipher response. Check out this for the usage:http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^]For simple requests you could also use fiddler or restclient(jar) apps.
9 May 2013 by tumbledDown2earth
Sync:http://msdn.microsoft.com/en-IN/library/d4cek6cc.aspx[^]Async:http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetrequeststream.aspx[^]
22 May 2013 by ashok yede201
I have created one NUnit project and I have test case which directly calls to the rest service and we can test that response with expected response.
10 Jun 2013 by Bernhard Hiller
"Continuous Integration" is the way to go along. That is, you'll need some other computer with a Continuous Integration software which polls your source code repository, updates its local sources, starts the builds of your projects, and also the unit tests, and then sends reports to you.Most...
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...
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...
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 ...
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...
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[^]
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[^]
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 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...
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.
4 Oct 2013 by Rob Philpott
Try [TestFixtureSetUp] instead of [Setup].
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 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/[^]
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
6 Mar 2014 by AndrewCharlz
try removing display:none after mouse hoverthis can the problem
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...
24 Mar 2014 by Keith Barrow
There are solutions to do this for you: See here[^] for a discussion on these.
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(); ...
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
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...
5 Nov 2014 by maheswaran_s_v
return communityChestCardArray[card].ToString() needs to be added in the actual method.
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...
29 Dec 2014 by Suvendu Shekhar Giri
There are a no of good tutorials available on the internet.Check following...
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: ...
24 Jun 2015 by Member 11749138
How to output the nunit test results to trx file in visualstudio 2012
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...
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...
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.
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...
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...
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...
22 Jun 2017 by Viktoriano
To provide a solution which helps to pass a necessary browser to Selenium WebDriver tests through the NUnit
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....
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 ||...
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...
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...
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...
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...
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)) { ...
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. ...
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...
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...
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();
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...