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

NUnit 

16 Apr 2013 by Sibsy
I am making a project and testing it for nUnit.Currently i have a persistant layer (BookingDA.cs), a business layer (BookingCreation.cs), a controller layer (BookingController.cs) and my nUnit test page (TestBooking.cs).pastebin of each code can be found...
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.
29 Aug 2017 by Valerii Tereshchenko
Asynchronous validation for MVVM(WPF)
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...
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() ...
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.
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.
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[^]
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...
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...
11 May 2016 by witnes
Examples of Mock usages
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.
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();
5 Feb 2024 by Mohammed Faci
Get started with Playwright using VS 2022/C# and NUnit
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...
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...
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...
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.
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...
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
10 Jun 2014 by MehraManish
unit testing of the view is not recommended
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 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...
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[^]
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
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. ...
24 Mar 2014 by Keith Barrow
There are solutions to do this for you: See here[^] for a discussion on these.
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: ...
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 aida1986
i'm working with Nunit not MS test and i want to have test class for this 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)) { ...
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. ...
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.
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...
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...
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...
24 Jun 2015 by Member 11749138
How to output the nunit test results to trx file in visualstudio 2012
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 :)
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 ?
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...
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#.
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.
29 Dec 2014 by Kranthi Kavuri
If anybody has notes on it, please share itThanks in advance.
29 Dec 2014 by Suvendu Shekhar Giri
There are a no of good tutorials available on the internet.Check following...
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
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/[^]
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/[^]
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...
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 ||...
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[^]
10 Jun 2013 by sencsk
Hi I'm using devexpress orm with VS2010. in my project contains lot of modules and projects. i plan to implement Nunit Test. I search it to google. i can find some basic ideas. that means how to start the app for ex: 1. We can create class liber. 2. Download Nunit Gui. 3. I write...
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...
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 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; ...
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) ==...
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: ...
3 Aug 2012 by PeteBarber
Integration Testing with NUnit and Entity Framework
25 Feb 2011 by Dipti Mehta
This is an introduction to NUnit and TDD
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...
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...
4 Apr 2024 by Mohammed Faci
How to leverage ChatGPT to Build an Automation Framework using the Page Object Model
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...
3 Mar 2014 by Sacha Barber
MsBuild and NUnit (a simple example)
19 Oct 2018 by Sean Rand
Getting the most from your test runner
11 Aug 2022 by Virendra S from Bangalore, Karnataka
public ProductConfigDetails GetProductConfig() { ProductConfigDetails ProdConfigDetails; if (appsettingsconfiguration.UseMockData) { taxConfigDetails =...
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...
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...
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"); ...
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 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?
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...
22 Jun 2017 by Viktoriano
New features overview of NUnit 3.7 version
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...
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...
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 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...
7 Oct 2012 by Nikhil_S
Here's The Link for NUnit TestCase Generator NUnit Test Case Code Generator[^]
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.
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();}