Click here to Skip to main content
15,886,873 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 

26 Apr 2011 by Abhinav S
I dont see why you should not be able to do unit test for this project.Perhaps you need to tell why you are confused that it may not be possible.
9 Jun 2011 by Abhinav S
Read this[^]. It helps understand the difference between a mock and a stub.
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/[^]
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...
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 ...
11 Sep 2013 by aida1986
i'm working with Nunit not MS test and i want to have test class for this method
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
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
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.
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.
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....
7 Oct 2012 by AmitGajjar
Hi,I have used Private objects in MS Unit test cases. do not have much idea about NUnit but this may work for you as well.Try to use PrivateObject class to access private object for testing. In below link i have list out some information on accessing private object.Creating Unit...
6 Mar 2014 by AndrewCharlz
try removing display:none after mouse hoverthis can the problem
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() { ...
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: ...
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
29 Apr 2013 by arvind_kg
Hi,i have a method which have two argument first the normal argument andthe second argument is the variable argument likepublic class TestClass{public bool TestMethod(string str,params int[] intarray){ return true;}}i have to stub this method how to do it,...
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....
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.
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 ?
7 Oct 2012 by Bernhard Hiller
You need "Reflection" - object instantiation and method calls have to be done via reflection. It is not such easy as with MSTest, but it can be done.
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...
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...
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.
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) ==...
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 May 2016 by DannyFreeman
Writing unit tests for a deep clone method
6 Jan 2017 by Debendra0256
In this article we will see one of the most important unit testing framework in DotNet.
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...
16 Feb 2024 by Dev Leader
Learn to create tests, use advanced techniques, and improve your code quality!
25 Feb 2011 by Dipti Mehta
This is an introduction to NUnit and TDD
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...
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?
16 Jun 2011 by erinpzk
Recently, I've been using Selenium to record a few simple tests. Although Selenium tests are initially stored as html files, the program allows you to export the test cases in a variety of languages (in this case, I'm using C#).I downloaded NUnit to use as my testing framework -- I can then...
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. ...
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.
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.
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...
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 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.
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...
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: ...
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[^]
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#.
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.
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...
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...
28 Nov 2013 by James Coleman
Leveraging Selenium and Image Magick to perform screenshot comparisons for UI regression testing.
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; ...
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"); ...
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 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.
29 Dec 2014 by Kranthi Kavuri
If anybody has notes on it, please share itThanks in advance.
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...
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[^]
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...
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[^]
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
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 ||...
5 Nov 2014 by maheswaran_s_v
return communityChestCardArray[card].ToString() needs to be added in the actual method.
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)) { ...
17 May 2011 by MBigglesworth79
This article is primarily for those of you who are new to unit testing and is intended as a basic introduction to unit testing and test-driven development; as well as how to write basic tests using the NUnit framework.
23 May 2012 by MD Niyaz Hashmi
How to debug nunit test cases in Visual studio 2010 Express edition?
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...
10 Jun 2014 by MehraManish
unit testing of the view is not recommended
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...
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...
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...
24 Jun 2015 by Member 11749138
How to output the nunit test results to trx file in visualstudio 2012
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"); ...
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...
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 );...
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...
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...
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...
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...
18 Mar 2011 by Member 4545580
Hi,I am trying to execute a NUnit test case (.Net 4.0 .dll, compiled against NUnit 2.5.9 ) using NUnit console in Windows 2008 R2 (X64) but it fails with below error message. Any idea?----System.Net.Sockets.SocketException: No connection could be made because the target machine...
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...
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
20 Dec 2011 by Member 8412182
How to apply NUnit in VS 2010.
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"); ...
25 Jan 2013 by micke.andersson
You could try MessageBox.Show("count " + countToString());
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...
5 Feb 2024 by Mohammed Faci
Get started with Playwright using VS 2022/C# and NUnit
4 Apr 2024 by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
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[^]
25 Jul 2013 by Neerajan Lamsal
Unit Testing using NUnit.
1 Mar 2011 by nguyen the trung
Dear all,I have a problem with NUnit: I have a testing project in vs2008 pro(C# language). My project work with Unit test tool in VS2008 but when I try to run it in NUnit, there is an error:"This assembly was not built with any known testing project"I have searched for this, it said...
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...
17 Jun 2012 by Nicky1984
Hi,I am currently working on Unit Testing, Stylecop custom rules, i tried to use NUnit V2.6 to test on my Stylecop rules, but i tried lots of time to convert Stylecop entity to string it doesn't work. below is the example code i was trying to work on [TestFixture] public class...
7 Oct 2012 by Nikhil_S
Here's The Link for NUnit TestCase Generator NUnit Test Case Code Generator[^]
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 ?
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
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 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. ...
29 Nov 2011 by Nupur Bakshi
Hello,I am working on Unit testing the MVC3 site using NUnit, MvcContrib.TestHelper package but I am facing the exception "Object reference not set to an instance of an object" when my test method accesses the controller having TryUpdateModel. I dont know what to do to pass the test. please...