Click here to Skip to main content
14,976,254 members
Everything / DevOps / Unit Testing

Unit Testing

unit-testing

Great Reads

by Fred Song (Melbourne)
Angular 7 with .NET Core 2.2 - Global Weather
by Anton Angelov
Code samples in C# how to assert DateTime with delta. Write your own Validator for MSTest or use built-in methods in NUnit.
by Naveen Kosana
Learn how to write unit test cases using Jasmine framework for Angular Controllers
by Indranil Pal
Mocking database in Unit Tests using Moq.

Latest Articles

by Łukasz Bownik
A simple method to estimate the quality of a unit test suite that can give some insight into the subject beyond regular test coverage.
by F-ES Sitecore
A discussion of what to unit test in your C# code and how to test it, including a section covering MVC
by Vassili Kravtchenko-Berejnoi
Use of a narrow-focus strategy in test-driven-development
by Paulo Zemek
I partially agree with the basic idea, but it fails when we need to deal with an issue no unit-test caught and the good developers and code-reviewers simply can't understand what's going on.

All Articles

Sort by Score

Unit Testing 

Please Sign up or sign in to vote.
9 Apr 2019
Fred Song (Melbourne)
Angular 7 with .NET Core 2.2 - Global Weather
Please Sign up or sign in to vote.
15 Sep 2015
Anton Angelov
Code samples in C# how to assert DateTime with delta. Write your own Validator for MSTest or use built-in methods in NUnit.
Please Sign up or sign in to vote.
18 Feb 2017
Naveen Kosana
Learn how to write unit test cases using Jasmine framework for Angular Controllers
Please Sign up or sign in to vote.
18 Oct 2012
Indranil Pal
Mocking database in Unit Tests using Moq.
Please Sign up or sign in to vote.
6 Jan 2021
Łukasz Bownik
A simple method to estimate the quality of a unit test suite that can give some insight into the subject beyond regular test coverage.
Please Sign up or sign in to vote.
19 Oct 2018
Sean Rand
Getting the most from your test runner
Please Sign up or sign in to vote.
6 Jun 2012
Sergey Alexandrovich Kryukov
No one can tell you the exact answer. It really depends on your project in further detail. I hope I don't have to proof that testing cannot proof anything? More exactly, you can proof there is a defect, but otherwise, if testing finds no defects, it cannot proof that all defects are fixed, no...
Please Sign up or sign in to vote.
3 Dec 2012
Vasil Trifonov
Getting console output within a unit test
Please Sign up or sign in to vote.
21 Jan 2013
Simeon Sheye
Beyond basic unit tests, how do you choose your tests and when are you done?
Please Sign up or sign in to vote.
2 Aug 2016
Richard Deeming
Your Calculation class does not contain a parameterless constructor. You need to pass the constructor parameters to the PrivateObject constructor[^]:string expression = "5*10-18/(3+19)";PrivateObject obj = new PrivateObject( typeof(Calculation), // The type of the object to...
Please Sign up or sign in to vote.
3 Oct 2012
Clifford Nelson
2 alternatives  
I have a file in my code (a library) that is required for running the code. In this case it is an XML file. Currently I have it in the root of the main program, and it works fine when running the code. However, I need this file for some information when running unit tests. How should I specify...
Please Sign up or sign in to vote.
12 Oct 2012
Clifford Nelson
Ends up that you can at least get the path for an assembly:string _testPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MdyPastTests)).Location);Thus can bypass the problems of the executing assembly in test, which can be very strange, and just use the location of some class.
Please Sign up or sign in to vote.
10 Mar 2018
Carlos Luis Rojas Aragonés
Formatting your rails specs with rspec_pacman_formatter
Please Sign up or sign in to vote.
21 Jun 2018
John M. Dlugosz
How can an automated test program test that something is rejected at compile time?
Please Sign up or sign in to vote.
11 Mar 2012
Andreas Gieriet
How to define RelationAssert as an extension to the VisualStudio Assert class.
Please Sign up or sign in to vote.
22 Oct 2012
Sergey Alexandrovich Kryukov
Those are just different tests, and you need both, to improve your chances to reveal some flaws. The more the better. That would be enough to wrap up the complete answer, but let's think what would be the background of these two different approaches.The application has some inner layers...
Please Sign up or sign in to vote.
19 May 2013
Yossi Yaari
A solution for monitoring Events called during test.
Please Sign up or sign in to vote.
16 Feb 2015
OriginalGriff
As little as possible should be static - excepting extension methods, which have to be, and some methods which are "generic" to an application rather than specific to a class.C# is an OOPs language - and the first "O" is for "Object"! If you make everything static, then you are ignoring what...
Please Sign up or sign in to vote.
25 Jun 2015
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 :)
Please Sign up or sign in to vote.
20 Sep 2020
F-ES Sitecore
A discussion of what to unit test in your C# code and how to test it, including a section covering MVC
Please Sign up or sign in to vote.
5 Feb 2013
Pete O'Hanlon
It's fairly straight forward testing a model with annotations in MVC. This[^] should give you a decent grounding in where to start. Pay particular attention to the section on the ValidationContext as this is the voodoo that really helps make it work.
Please Sign up or sign in to vote.
10 Feb 2013
Enrique Albert
Pattern to follow using mock frameworks so non public methods can be tested. The code example is based on the RhinoMock framework but it is easily applicable to any other mock framework.
Please Sign up or sign in to vote.
21 May 2013
cynthia_dunlop
Service virtualization undeniably benefits the development process, but it can be both a blessing & a curse for developers. Learn how to minimize the burden on development to achieve maximum acceleration of delivery cycles.
Please Sign up or sign in to vote.
5 Jun 2013
Prasad Khandekar
Hello,You can use Selenium IDE. This link also lists some other tools for finding security related issues and are worth considerations.Regards,
Please Sign up or sign in to vote.
4 Jul 2013
bbirajdar
You should start here What is software testing[^]
Please Sign up or sign in to vote.
28 Aug 2013
Fredrik Bornander
NUnit[^] is a .NET unit test framework, if you're targeting the .NET framework then using this makes sense.CppUnit[^] is a C++ unit test framework, it's applicable for pretty much anything written in C++ (with the possible exception for managed C++).Hope this helps,Fredrik
Please Sign up or sign in to vote.
14 Jan 2014
Nanda Kumar Chintam
This tip explains how to perform unit testing for business logic written in App_code for a website project.
Please Sign up or sign in to vote.
23 Feb 2014
Kornfeld Eliyahu Peter
Not all editions of Visual Studio 2010 support unit test. Even you can open solutions with unit test in it on every edition, it will run only on Premium and Ultimate editions...
Please Sign up or sign in to vote.
24 Mar 2014
Alexander Dymshyts
I have a method that I want to test with moq:public List GetValidRecords(Entities context) where T: class, IGetListOfTables{ try { return context.Set().Where(x => x.Valid == 1).ToList(); } catch (Exception ex) { throw new...
Please Sign up or sign in to vote.
27 Aug 2014
Valery Possoz
Hello,You could do it using delegates in your unit tests.for example: [TestMethod] public void EventShouldBeRaised() { ClassToTest classToTest = new ClassToTest(); bool eventRaised = false; classToTest.EventRaised +=...
Please Sign up or sign in to vote.
28 Sep 2014
Gediminas Geigalas
Expose your mocks directly from the Fixture Object if possible. If there is no real need to complicate things by converting types and introducing extension methods, don’t do it.
Please Sign up or sign in to vote.
28 Sep 2015
jeron1
Why reinvent the wheel, a quick google turned up this[^]. I am certain there are lots of others as well.
Please Sign up or sign in to vote.
24 Oct 2015
CPallini
Why your function doesn't return a std::string (as it should)?What's the purpose of the std::map (or, better, what's the purpose of myMap while you can use a std::map?)?
Please Sign up or sign in to vote.
3 Jan 2016
George Swan
How to replace the System.Timer with a mock object when testing
Please Sign up or sign in to vote.
11 Jan 2016
Asutosha
1 alternative  
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 ?
Please Sign up or sign in to vote.
26 May 2016
Patrice T
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.The debugger allow you to follow the execution line by line, inspect variables and you will see that there...
Please Sign up or sign in to vote.
24 Oct 2016
F-ES Sitecore
Pick one scenario at a time, set the entity properties up such that that scenario is satisfied, then check the entity properties that match the scenario have been set up.eg you'll first want to check when InterpreterCostAuthorised is true and InterpreterCostAuthorisedDate is null, so set...
Please Sign up or sign in to vote.
18 Jan 2017
Sergey Podobry
How-to guide about using KmTest for writing kernel-mode unit tests
Please Sign up or sign in to vote.
23 May 2017
F-ES Sitecore
Asserts are what is used to cause a test to fail, if none of your asserts cause the test to fail then the test is a success. So if you don't have any asserts at all the test is bound to pass (assuming no exceptions are raised as most test frameworks consider an exception to be a fail too unless...
Please Sign up or sign in to vote.
13 Jul 2017
Super Superman
I'd recommend switching over to xunit for your .NET Core unit tests. You can run xunit tests directly from JetBrains cross-platform .NET IDE "Rider"[^]. Alternatively, you can run xunit tests from the command line using the following command: $ dotnet xunit See: Getting started with...
Please Sign up or sign in to vote.
28 Aug 2018
Richard MacCutchan
The different types of test projects are designed specifically for the different languages. You can only use one of the options that target C++.
Please Sign up or sign in to vote.
2 Apr 2019
IlanGreen
4 alternatives  
I just started a new job as a junior .Net developer and my first task is to cover a solution that has 80% success with unit-tests, in order to assure every piece of code is working correctly. I was able to make it to 37% after covering all public methods by simply calling them from my tests, but...
Please Sign up or sign in to vote.
3 Apr 2019
GregoryPres
Our team uses Typemock's Isolator as a mocking framework and it has the ability to test private methods. Simple Api for verifying private method calls: Isolate.Verify.NonPublic.WasCalled(, "PrivateMethodname"); Also, you can fake private instances and change their behavior which will help you...
Please Sign up or sign in to vote.
22 Feb 2020
OriginalGriff
See here: The Differences Between Unit Testing, Integration Testing And Functional Testing[^]
Please Sign up or sign in to vote.
9 Mar 2020
#realJSOP
You could load the excel file and the database table's schema into separate ADO datatables, and then compare the schemas between the datatables. Depending on how extensive your data type discovery is during the import process, you could also...
Please Sign up or sign in to vote.
23 Jun 2020
Richard MacCutchan
I have been looking at the Google Test documentation, and I think your test code is not correct. The test needs to call the function to be tested, and verify the results. See googletest/primer.md at master · google/googletest · GitHub[^] for the...
Please Sign up or sign in to vote.
13 Jun 2021
Member 13927839
When I joined my company as a newcomer, I was exploring the unit test suite of the product code. It uses the gtest framework. But when I checked all the tests, they were testing the whole functionality by calling real functions and asserting...
Please Sign up or sign in to vote.
8 Feb 2012
Member 4391175
Hi,When i clicked the Button one modal pop up dialog box will open, how to click that open button using watin test.I used below code , but it doesn't working for me. public void CheckName() { IE ie = new IE("http://localhost:4066/SampleWebSite/Default.aspx"); ...
Please Sign up or sign in to vote.
22 Feb 2012
Erik Rude
1 alternative  
I'm a bit new to unit testing, most of my tests are fairly easy to do and just works brilliantly. However I'm trying to test this simple function and it fails me with the following error: System.NullReferenceException: Object reference not set to an instance of an object.What am I doing...
Please Sign up or sign in to vote.
8 Mar 2012
SwapnadipSaha
hi all, Recently I have joined an IT company. and I've to face an exit test next week on the following topics1. Basics of MVC2. Integration of Entity Framework, MVC, AJAX and Jquery3. Repositories4. Unit Of Work5. Unity Framework6. Data Manager7. Data...
Please Sign up or sign in to vote.
11 Mar 2012
Member 9648718
How can i make a test expecting an exception to be thrown.here is my code : [ExpectedException(typeof(Exception))] public void AnAddressHasOnly1UserTest() { Address address = new Address() { Street ="street1", ...
Please Sign up or sign in to vote.
17 Mar 2012
Dean Oliver
Check these links out.http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx[^]http://msdn.microsoft.com/en-us/library/a65txexh.aspx[^]
Please Sign up or sign in to vote.
8 Apr 2012
Kranthi Boppana
Hi All,Is it possible to implement Unit test for Validations in silverlight using MVVM??If yes, please help me out with an example!Any help would be appreciated.Thank you,Kranthi Boppana
Please Sign up or sign in to vote.
6 Jun 2012
Stephen Hewison
1 alternative  
Hi,I have a question about finding the best balance of unit testing. I have in one example a website which consumes a services for its data. If I break the solution down I have the following layers:ServiceData Access LayerBusiness Logic LayerService API LayerWebsiteService...
Please Sign up or sign in to vote.
5 Jul 2012
Karthik. A
The error "Cannot override Non-Virtual member ...ProductRepository" indicates that Moq is attempting "override" a method that is not virtual. So a method w/ definitionpublic void Something() { ... }cannot be overridden. But this can be :public virtual void Something() { ......
Please Sign up or sign in to vote.
26 Sep 2012
Rohith Gopi
Hi,I want to unit test a subroutine.The code is like this. Public Sub UpdateChat() 'Getting the connection string Dim connectString As String = ConfigurationManager.ConnectionStrings("ShoutDb").ConnectionString 'Creating connection object Dim...
Please Sign up or sign in to vote.
3 Oct 2012
AssemblySoft
Hi Clifford,Could you not add the xml file to your unit test project, similar to how we add library references in order to allow our unit test projects to gain visibility into our application or possibly add the xml file to the bin directory of your unit test project or a known directory and...
Please Sign up or sign in to vote.
22 Oct 2012
Blakej777
1 alternative  
Is it preferred to use the real UI or should it be mocked in AAT? Currently, i mock out my view for my unit/integration testing, but should i for automated testing? I can't seem to find any articles about this online. Mostly relates to Unit-testing specifically.
Please Sign up or sign in to vote.
31 Oct 2012
Pablo Aliskevicius
IMHO:1. You should test the base class independently, before you test the derived class.2. Testing for a null parameter is nice, but you should also test that, given valid parameters, the result of your function (not this one, but others that are not void) is the one you expect, and the...
Please Sign up or sign in to vote.
28 Nov 2012
Sergey Alexandrovich Kryukov
chuckdawit wrote:Should I replace the 'SomeObjectIveCreated2' with an interface to adhere to rules of encapsulation? This is helpful for unit testing but is more for the rules regarding the S.O.L.I.D principles.You should understand that interfaces, as opposed to abstract classes and "classic"...
Please Sign up or sign in to vote.
1 Jan 2013
Vijay_Gurunanee
3 alternatives  
Hi,In order to remove external dependency for testing purpose i was trying to implement the mole frameworkeverything was working fine until i have moled the class with static readonly property.Creating mole of that class is not the root cause of issue but that readonly property is...
Please Sign up or sign in to vote.
1 Jan 2013
Abhinav S
You could try using the MolesEraseStaticConstructor.More about it here - http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf[^].
Please Sign up or sign in to vote.
10 Jan 2013
Rupa1
1 alternative  
how can i set Application variable to mock data
Please Sign up or sign in to vote.
10 Jan 2013
Sandeep Mewara
Following might help: Mocking HttpContext for Unit Testing[^]
Please Sign up or sign in to vote.
23 Jan 2013
Alpman
I have a question about generating a new type while writing a unit test in Visual Studio 2010.I have a project "Donk" for the code and a test project "DonkTest" for the unit tests. The test project has a reference to the project "Donk".In my unit test I write something likeDonk d =...
Please Sign up or sign in to vote.
28 Jan 2013
scarletwitch1990
1 alternative  
my visual web developer is installed without the unit test framework. Which of the extensions should i use instead?the version of the web developer is 2010. Please help...
Please Sign up or sign in to vote.
28 Jan 2013
Abhinav S
To install the unit test framework, you will need to reinstall Visual Studio.Note that the framework is not available in the express editions.
Please Sign up or sign in to vote.
5 Feb 2013
scarletwitch1990
1 alternative  
I was trying the NerdDinner in mvc 4 and at the particular code below: Assert.IsInstanceOfType(typeof(ViewResult),result); i am getting an errorNUnit.Framework.Assert.IsInstanceOfType(System.Type, object)' is obsoleteBecause of this unit tests are failing and are throwing a Null...
Please Sign up or sign in to vote.
31 Jan 2013
Sergey Alexandrovich Kryukov
This method is declared obsolete, because, after introduction of generics as early as of .NET v.2.0, non-generic methods depending on types simply make no sense, they are just too bad next to generic ones.Beginning with NUnit 2.5, generic equivalents are available: IsInstanceOf,...
Please Sign up or sign in to vote.
3 Feb 2013
Abhinav S
For unit testing the BLL, you can always consider using the Microsoft Visual Studio Testing Framework or a third party like Nunint.For a mocking framework, you can consider using Moles[^].
Please Sign up or sign in to vote.
5 Feb 2013
scarletwitch1990
1 alternative  
Can we create test methods for model properties with model validations. e.g.public class PersonAccount{ [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "New...
Please Sign up or sign in to vote.
5 Feb 2013
Sergey Alexandrovich Kryukov
This is what it is: you did not provide matching method declaration in some partial class declaration. As you don't mention about it, I would be curious to know what was your idea about it. Partial methods are as trivial as...
Please Sign up or sign in to vote.
21 Feb 2013
scarletwitch1990
below is my repository service public class ProductService : IProductService { private IProductRepository _productRepository; // Some initlization stuff public Product GetProduct(int id) { try { return _productRepository.GetProduct(id); } catch...
Please Sign up or sign in to vote.
22 Feb 2013
scarletwitch1990
My application has a BaseController in which the HttpContext.Current.Session[CacheKey] is used.how do i mock the above session while unit testing.I have the fake HttpContext Helpers...how do i use them....also my HttpContext.Current.Session[CacheKey] manages the language of the browser...
Please Sign up or sign in to vote.
6 Mar 2013
scarletwitch1990
i have a service lyk below:public class SubjectService : ISubjectService { private readonly ISubjectRepository subjectRepository; public SubjectService(ISubjectRepository subjectRepository) { this.broadSubjectAreaRepository =...
Please Sign up or sign in to vote.
26 Feb 2013
scarletwitch1990
1 alternative  
hello i was unit testing my service layer :I have a service layer named "CustomerService"public interface ICustomerService{ IQueryable GetCustomerByFilter(Expression> where);}public class CustomerService : ICustomerService{ private...
Please Sign up or sign in to vote.
26 Feb 2013
scarletwitch1990
1 alternative  
during one of my lectures in unit testing, my professor stated that testing a controller action comes under functional testing, and that the best practice to test the controller is to unit test the various independent functions that we are using in it like the service layer functions.we are...
Please Sign up or sign in to vote.
28 Feb 2013
scarletwitch1990
1 alternative  
Say my controller class is inheriting from a basecontroller instead of controller like shown below: public partial class ProductController : BaseController { public ActionResult Index() { //Code to the controller action } }And my...
Please Sign up or sign in to vote.
12 Mar 2013
K C R
1 alternative  
My project is a web forms application. Currently we do integration testing and selenium web testing ( For UI ) and now ma Manager has asked us to do unit testing instead of selenium for code coverage. My question is how do we do unit testing for web forms (and... what is mock ?), would be gr8 if...
Please Sign up or sign in to vote.
8 Apr 2013
吴骏明
Generate interface for WebService client stub for unit testing.
Please Sign up or sign in to vote.
29 Apr 2013
jophyjob
Hello All , We have a WPF application Project which is suppose to run on different OS versions (Win XP ,Win 7 and Win 8 ). To make sure the compatibility of the application on all OS , We like to Run some unit test on All these OS versions On the TFS check-In . ...
Please Sign up or sign in to vote.
2 May 2013
Gautam Raithatha
1 alternative  
I have created a test project for unit testing the methods in my c# project and various test methods in it. In actual method, there are global class level variables used whose values are set from constructor or other methods. So when actual project runs, the variables have value when referenced...
Please Sign up or sign in to vote.
2 May 2013
tumbledDown2earth
This is a classic case. You can make the global dependent variables in a config (or some container class) which implements an interface. Now in the live example implement your interface with a config reader class and your methods should read these values from the interface only.You can...
Please Sign up or sign in to vote.
9 May 2013
ashok yede201
1 alternative  
Hello,I have created one RESTful wcf srevice.I wanna to know best Unit testing tool to test Rest Wcf Service.I was trying to use NUnit test tool, but I thought it is not best tool to test REST wcf Service as I was getting many errrors.Please tell meThanks in advance.
Please Sign up or sign in to vote.
9 May 2013
Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Check out the below articles. Best methods are explained here.1. Walkthrough: Build, Host, and Test Simple RESTful WCF Service[^].2. Building and Testing WCF RESTful services[^].3. RestFul WCF JSON Service with client and on Mozilla Firefox –REST Client[^].
Please Sign up or sign in to vote.
15 May 2013
Vijay_Gurunanee
Sorry for late reply...but not working for me....I just re factored the code and changed my code such that it can be moled.But still i didn't find proper solution for this problem...Thanks...
Please Sign up or sign in to vote.
20 May 2013
Andreas Gieriet
If you need to know how many times an external interface method is called, use some mocking framework. See also What C# mocking framework to use?[^].These frameworks provide means to assert how many times and with what parameters you expect the method to be called.If the method is an...
Please Sign up or sign in to vote.
4 Jun 2013
KishoreUHG
Hi,I have a test method in the Unit test project. When i try to run the below method[TestMethod()] [HostType("ASP.NET")] [AspNetDevelopmentServerHost("C:\\Samples\\MyUnitTestApp\\MVCApp", "/")] [UrlToTest("http://localhost:59794/")] public void...
Please Sign up or sign in to vote.
5 Jun 2013
amnk.info
try firebughttps://addons.mozilla.org/en-US/firefox/addon/firebug/[^]
Please Sign up or sign in to vote.
19 Jun 2013
Vijay_Gurunanee
I have gone for many articles and discussions but did not found any perfect solutions.So for now considering that it is not possible to override the private read only static properties of a sealed class. (Yes in my case, class sealed...)So i have decided to change the design of class and...
Please Sign up or sign in to vote.
26 Jun 2013
A. K. Das
2 alternatives  
Dear AllIs It possible to unit test, constructor in c#, if yes how if not why Plz response .Thanks
Please Sign up or sign in to vote.
26 Jun 2013
bbirajdar
Yes.. Its possible Unit testing and the "constructors do nothing" rule[^]
Please Sign up or sign in to vote.
26 Jun 2013
Ron Beyer
Yes, you do this by instantiating the object and then asserting the fields of the object are initialized properly. You can also assert that no exception was thrown during the constructor. You can check private fields through reflection if you need to.In your case it depends on what you want...
Please Sign up or sign in to vote.
4 Jul 2013
Yesudasan Moses
2 alternatives  
Hi,I am developing a Windows Application using C# in Visual Studio 2012.What are the methodes to test it ? I dont know anything about Software Testing... Thanks
Please Sign up or sign in to vote.
4 Jul 2013
Nirav Prabtani
see this..:)http://stackoverflow.com/questions/9097044/advice-on-unit-testing-a-windows-forms-application[^]http://blog.somecreativity.com/2008/11/06/automating-windows-forms-ui-testing/[^]http://stackoverflow.com/questions/11274221/testing-a-net-windows-forms-vb-app[^]
Please Sign up or sign in to vote.
28 Aug 2013
Rahul from Poona
1 alternative  
What is difference between CPPUnit and NUnit?When to use CPPUNIT and when to use NUNIT?What will be appropriate for C++ ATL COM project and why?Thanks in advance
Please Sign up or sign in to vote.
3 Sep 2013
kishore.koorma
1 alternative  
Hi,I am new to writing unit test case manually, please suggest me any one how to wright with example.
Please Sign up or sign in to vote.
3 Sep 2013
ridoy
So you need to start from these :How to: Create an ASP.NET Unit Test[^]A Unit Testing Walkthrough with Visual Studio Team Test[^]ASP.NET Unit Testing[^]Unit Testing ASP.Net Applications with Visual Studio 2008[^]
Please Sign up or sign in to vote.
13 Sep 2013
greysnitin
Hi, I have 2 ms tests in 2 separate test classes. These tests sometimes just gets Aborted. It doesn't throw any exception.I do found a common thing between those 2 test cases, both in between there execution creates an instance of view (.xaml).I do not found any place where it's mentioned do...
Please Sign up or sign in to vote.
25 Nov 2013
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.
Please Sign up or sign in to vote.
25 Nov 2013
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/[^]
Please Sign up or sign in to vote.
1 Dec 2013
pa.dhruv
2 alternatives  
I have a situation where I need to add unit test to my application which verifies strong naming.I need to put a unit test to this application which would check if the current application is strongly named or not. I just want to get started with this is there any library which can be added to...
Please Sign up or sign in to vote.
2 Dec 2013
johannesnestler
Maybe you find this useful:http://blog.codingoutloud.com/2010/03/13/three-ways-to-tell-whether-an-assembly-dl-is-strong-named/[^]I think you could write some convenient wrapper arround the sn.exe tool for use in your unit-tests...
Please Sign up or sign in to vote.
2 Dec 2013
pa.dhruv
I think it can only be done by using the sn.exe in my tests and matching the outputs.
Please Sign up or sign in to vote.
11 Dec 2013
Imran Khan Pathan
2 alternatives  
Hi AllI am going to write Unit Test in my project. I am using ADO.NET application block library to perform database operation. I want to write Test Methods for Insert, Update and Delete methods. My requirement is after inserting or updating dummy records in database, I want to clean up...
Please Sign up or sign in to vote.
12 Dec 2013
thatraja
You didn't share any details about method. Write appropriate query(DELETE) in TestCleanUp method.But don't disturb development database. Create a copy for testing. Check this articleCreate a Sample SQL Database in Less Than 2 Minutes[^]
Please Sign up or sign in to vote.
12 Dec 2013
BobJanova
If the code you're testing talks to a database, by definition that is not a unit test (it's an integration test). Are you actually testing the database access code here? If not, you want to put the database access code behind an interface and use a mock database provider for the unit tests of...
Please Sign up or sign in to vote.
18 Dec 2013
Vinodh.B
Hi Can any suggest how to do Microsoft unit test for the viewmodel in silverlight . Please refer the follwing code . TEchnologies . Silverlight 4.0MVVM ENtityWCF . Test page code . [TestClass] public class TestClass1:SilverlightTest { [TestMethod] ...
Please Sign up or sign in to vote.
19 Dec 2013
Imran Khan Pathan
Hi All,I just need information about code coverage of webservice method that includes Async Methods as well.Suppose, I have one method written in WebService, MethodOne(string Value) and I have written TestMethod to check code coverage for this method,When I run Test and check in code...
Please Sign up or sign in to vote.
9 Feb 2014
__Veereshkumar
HiI was breaking my head over it for the past hour and finally found it. :)U just have to create a default.aspx page in your web service project..!following is the link that should solve your doubt...http://msdn.microsoft.com/en-us/library/ms243399(v=vs.90).aspx
Please Sign up or sign in to vote.
11 Feb 2014
harleydk
Mocking Session State in an ASP.NET MVC4 Unit Test using Moq
Please Sign up or sign in to vote.
19 Feb 2014
Priya Kakar
Can we create Coded UI test cases in VS premium/ultimate version and use it in Professional version? i googled it and found some links supporting that its possible, using MTM. I'm a newbie to this. so, if somebody can help,then i shall be obliged..Thanks!
Please Sign up or sign in to vote.
26 Feb 2014
miligupta123
HI,I am writing unit test cases for repositories using Microsoft fakes,in which one of the repository have unityresolver which throws errors.Below is mu code for Unity Resolver.public static TUnityType Create(){ return...
Please Sign up or sign in to vote.
9 Mar 2014
Member 10471717
Hi,We have a PRISM based MVVM Silverlight application(SL5).The idea is to create unit tests for the viewmodel and in some places view code.We explored msTest, nunit and Silverlight unit test framework for the same and reached a conclusion that Silverlight unit test only work with our...
Please Sign up or sign in to vote.
10 Mar 2014
Ganeshaspy
1 alternative  
I am learning Test Driven Development and trying to use Moq library for mocking. What is the purpose of Setup method of Mock class?
Please Sign up or sign in to vote.
10 Mar 2014
Bernhard Hiller
Somewhere in the code, methods or properties of the mocked object will be accessed. What is the mocked object expected to do then? The Setup methods are used for that purpose: they tell the mocked object what to do here.Example: I have an object with a property, and the code will call the...
Please Sign up or sign in to vote.
25 Mar 2014
JS00001
[TestMethod] public void UnitTestMethod1() { Test1Controller controller = new Test1Controller(); //This call throws NullReferenceException "Object reference not set to an instance of an object." WebSecurity.Login("User1", "password1"); ...
Please Sign up or sign in to vote.
6 Apr 2014
Mike114
How to setup unit test environment on Amazon Elastic Bamboo instance
Please Sign up or sign in to vote.
14 May 2014
kamalcodeproject
Hi,I need to write a VS unit testing for the public method which present in the classA.ClassA dont have default constructor, it is having parameterzed constructor; parameter as Web Page.As to write VS unit testing for the method, we need to create web page and create instance by passing...
Please Sign up or sign in to vote.
29 May 2014
NaveenChidara
I'm able to create mock objects and do a update test with mocked entities successfully.But the issue is with create test. Here is my sample code.In this always my testPG is null and so the test failsbase class:public class TestContext where T : class { protected Mock...
Please Sign up or sign in to vote.
10 Jun 2014
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
Please Sign up or sign in to vote.
23 Jul 2014
Vivek S Kale
Hi,i have a scenario where "if I change the date from date picker, pop up should appear" how to test this..
Please Sign up or sign in to vote.
27 Aug 2014
Mehdi Gholam
To write unit test you should :1) Define what the correct input and output combinations should be.2) Write tests for each combination.Since your class is domain specific there is little we can help you with, try contacting the designer of the class or your supervisor.To write...
Please Sign up or sign in to vote.
27 Aug 2014
Duncan Edwards Jones
1 alternative  
I have a class that raises an even when its internal state changes (broadly similar to INotifyPropertyChange but slightly different).How should I write a unit test that verifies that this event is indeed raised? (There's nothing in the same model as "ExpectedException" for events?)
Please Sign up or sign in to vote.
13 Sep 2014
Commish13
2 alternatives  
Hi,I don't know if I'm using the correct terminology, but I'm trying to use a unit test, or just a C# class file to pull records from an excel file(sheet) and insert them into a sql Database. Does anyone know of a good tutorial, book, or any resource at all I could learn how to do this. Also...
Please Sign up or sign in to vote.
13 Sep 2014
Garth J Lancaster
You probably want a Project/Solution with 1) a class to parse the data (see below), and then 2) a 'Database Layer' which can all be in one class for such a simple requirement, to connect to and add data to the table (it might also need to create the table(s) etc)I'd save the data as a...
Please Sign up or sign in to vote.
16 Sep 2014
kanjolia gopal
Hi Check this given Link http://www.c-sharpcorner.com/UploadFile/99bb20/import-excel-data-to-sql-server-in-Asp-Net/
Please Sign up or sign in to vote.
21 Oct 2014
Member 11169453
1 alternative  
I've calls to my data access from another class.So while implementing moq I have :var mockdac = new Mock();mockDac.SetUp(o => o.MyMethod(params)).Returns("something");Inside MyMethod I have :var reader = Database.ExecuteReader(cmd);while(reader.Read()){ //Some logic}My...
Please Sign up or sign in to vote.
25 Oct 2014
Tomas Takac
For what's worth, I wrote this article based on your question: IDataReader Stub[^]
Please Sign up or sign in to vote.
5 Nov 2014
DecompileCodex
1 alternative  
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...
Please Sign up or sign in to vote.
5 Nov 2014
maheswaran_s_v
return communityChestCardArray[card].ToString() needs to be added in the actual method.
Please Sign up or sign in to vote.
13 Nov 2014
QAVN Parallels
After a test method failed, there is a Message about this failure in the "Test Explorer" window. It will look like belowTest Failed - TC0001 Message: Test method ParallelsAutomation.TestCases.APS2.UnitTest1.U1TC_001 threw exception: System.DivideByZeroException: Attempted to divide by...
Please Sign up or sign in to vote.
13 Nov 2014
ASRAAR
Hi , I want to test a static method which is invoking another static method from the same class. For example , we have class A and it has two static methods method1() and method2() both are static . Let's suppose method1() is getting invoked from method2(). How can I write a test case for...
Please Sign up or sign in to vote.
17 Nov 2014
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...
Please Sign up or sign in to vote.
21 Nov 2014
qwerty 2
Hi I need to generate a trx file through VS tests which should contain the test case attributes like owner, description using command line optionsThe above attributes are generated by default in MS tests.I tried using custom logger to log the info but am not able to get the owner and...
Please Sign up or sign in to vote.
21 Nov 2014
qwerty 2
Hi I need to generate a trx file through VS tests which should contain the test case attributes like owner, description using command line optionsThe above attributes are generated by default in MS tests.I tried using custom logger to log the info but am not able to get the owner and...
Please Sign up or sign in to vote.
1 Dec 2014
Karthik Ravi
2 alternatives  
Hi,I am tring to unit test my project but it showing error as "Object Reference not set to an instance of an object". someone kindly give me a solution for this problem.I referred all necessary namespace in this project. //Unit Test codeusing System;using...
Please Sign up or sign in to vote.
2 Dec 2014
OriginalGriff
"i think it may be on "Source Con" in TestConnection method. " Source Con = null;Can't throw a null reference exception - it doesn't refer to or create an instance of any class.However, then next line is likely to: appGlobal.AddText();Check your references to...
Please Sign up or sign in to vote.
2 Dec 2014
Sergey Alexandrovich Kryukov
You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown. You should not ask a specific question each time you face this little problem. It's much more important to learn how to deal with it all by yourself in all cases. Not to...
Please Sign up or sign in to vote.
9 Dec 2014
anssary2010
if there is article in simple detail explorer Repository pattern and what is the mean of Loosely Coupled
Please Sign up or sign in to vote.
17 Dec 2014
George Jonsson
This is an impossible question to answer without any knowledge about the test sequencer you are using or what kind of API the vendor is providing.You are not saying if you want to do this from within a test method or by using an external application, for example for the purpose of automate...
Please Sign up or sign in to vote.
28 Dec 2014
Thomas Maierhofer (Tom)
2 alternatives  
I have to test the behavior of components when executing parallel operations. I haven't found a library / toolbox / unit test extension helping me doing this.I want to produce exact execution sequences in the parallel code fragments, so I could do this with events manually. But this is very...
Please Sign up or sign in to vote.
31 Dec 2014
Thomas Maierhofer (Tom)
As it turned out, that no solution exists which matches my needs, I used the remaining days of the year to write a concurrency test helper. This is from the unit tests and it shows three parallel code blocks that are executed, synchronized and analyzed using the test helper class: ...
Please Sign up or sign in to vote.
16 Feb 2015
User 11197367
1 alternative  
Hi guys.I'm a beginner, and as far as I know the Code Entry Point has to be static. But you can only reference static variables and static methods within theese static Main class.I didnt made big multithreading yet, so I basically made absolutely everything static. Now I'm starting with...
Please Sign up or sign in to vote.
23 Feb 2015
Member 11447944
1 alternative  
So i just started to learning unit testing in IOS and i have few simple tasks to complete.So basically i have created a Tab bar controller with only two tabs. How can i test that there indeed only two tabs ?Also, i have an order: The first tab and the second tab How can i test the order...
Please Sign up or sign in to vote.
23 Feb 2015
KarstenK
At first testing has changed somehow on Apple systems. ReadAbout Testing with Xcode.You can assign the Tabbar to an outlet an than access the array of tabs. To start Testing, use on the Menu Product -> Test or Product->Build for Testing. Testing only runs on the simulator. If to feasable,...
Please Sign up or sign in to vote.
6 Apr 2015
Prasad Kalamkar
2 alternatives  
I am doing the unit testing of application service using Xunit.net.My unit test case is not getting partially executed because of following statement: StringCipher stringCipher = new StringCipher();StringCipher is class in which I have written the logic for password encryption and...
Please Sign up or sign in to vote.
6 Apr 2015
Prasad Kalamkar
I have copied appsettings values to my test project class.
Please Sign up or sign in to vote.
7 Apr 2015
CHill60
An alternative to just copying the appsettings to the test project is as follows:In your test project right-click, Add, Existing Item.Navigate to the App.Config for the project you are trying to test.Instead of just clicking "Add" click the down-arrow next to it and select "Add as...
Please Sign up or sign in to vote.
10 Apr 2015
Mehdi Gholam
There is a little thing in every language known as a loop.for(int i = 0 ; i{ // you can figure out the rest!}
Please Sign up or sign in to vote.
11 May 2015
gsdvenkatesh
2 alternatives  
Hello,I am starting to write unit tests for my web application. I am confused in choosing the best mocking framework for it. I am using DevExpress controls all through my application and unfortunately they don't have a mocking framework. What is the best mocking framework that i can use...
Please Sign up or sign in to vote.
11 May 2015
gsdvenkatesh
Found this link to be very helpful - http://stackoverflow.com/questions/9677445/mock-framework-vs-ms-fakes-frameworks[^]
Please Sign up or sign in to vote.
11 May 2015
F-ES Sitecore
Most people use moq or rhinomock. Moq probably edges it for me, the main difference is in the syntaxes and what seems to make more sense to you. What's more important that which one you choose is that you fully get to grips with how you use it to mock various things, they're all much of a...
Please Sign up or sign in to vote.
13 May 2015
Serhiy Koza
I have multiple props like this: public static bool ForwardMessagesToEmail { get { string forwardToEmail = WebConfigurationManager.AppSettings["ForwardToEmail"]; return String.IsNullOrEmpty(forwardToEmail) ? false : forwardToEmail.ToLower() ==...
Please Sign up or sign in to vote.
13 May 2015
jmulberry
I am part of a small tech company and was doing manual testing for them. They have now switched me over to Unit Testing in C# for some of the developers. The devs are rather young and know little to nothing about Unit Tests and I am having a hard time finding answers to my questions. I have done...
Please Sign up or sign in to vote.
29 May 2015
jmulberry
I have a few unit tests that when I run all 700 together they pass but when I run them by there manager they fail. I have Visual Studio 2013 and R# 8.Manager Code:public GPermission CreatePerm(string user, string gId, string org, GPerm permissions) { ...
Please Sign up or sign in to vote.
24 Jun 2015
Member 11749138
1 alternative  
How to output the nunit test results to trx file in visualstudio 2012
Please Sign up or sign in to vote.
30 Jun 2015
Ibrahim ben Salah
This tip describes how to write Selenium based tests while allowing you to mock/fake parts of the server components.
Please Sign up or sign in to vote.
16 Jul 2015
Karthik Gunasekaran
In our application, we have created Selenium test methods for many modules through C# Unit Test projects. We have configured all the selenium test methods with test categories(with sub-module info, smoke-test, regression-test, etc.,).From web interface, we would like to set some configs for...
Please Sign up or sign in to vote.
28 Jul 2015
Sergey Alexandrovich Kryukov
Do you mean measurements units? No. Basically, you have to do such simple calculations by yourself. This is not really difficult.This topis was a matter of hot discussions years ago, but I see no serious proceedings in this direction, because — why would it be more important than any other...
Please Sign up or sign in to vote.
28 Sep 2015
Patrice T
Last time I used it, Putty was a telnet utility. And telnet is char mode only.This makes the question meaningless.As far as I know there is no link between C++ and Putty and Putty don't do bar codes.I guess you really need to improve your question
Please Sign up or sign in to vote.
15 Oct 2015
zhshqzyc
2 alternatives  
I have a class. public class VoiceElementsLine : ILine { public Guid LineId { get; set; } public TelephonyServer TelephonyServer { get; set; } public virtual ChannelResource ChannelResource { get; set; } public LanguageData LangInfo { get; set; } ...
Please Sign up or sign in to vote.
15 Oct 2015
Jesús Álvarez
I supose your class ChannelResource dont have a default constructor or empty, public void ChannelResource(){}
Please Sign up or sign in to vote.
15 Oct 2015
Jesús Álvarez
you need to implement all mehtos of teh interface, public void Hangup(){} is not implement yet
Please Sign up or sign in to vote.
24 Oct 2015
User 59241
To me the code does not look ready for unit testing.http://stackoverflow.com/questions/2931704/how-to-compare-string-with-const-char[^]while( s != myMap[i])
Please Sign up or sign in to vote.
26 Oct 2015
bling
Your memory leak isn't a real memory leak.Most heap checking tools will report a program like the following as having a leak.#include static char *leaks;int main(int argc, char *argv[]){ leaks = strdup("leaked data"); puts(leaks); return 0;}If it...
Please Sign up or sign in to vote.
8 Dec 2015
pratik015
1 alternative  
I am writing a unit test case for my application.In my application, I am using SQLite datebase.I want to mock following methods.Like,ExecuteNonQuery, ExecuteScalar, GetDataSet.I am writing my methods below.Please, any one help me to write mock unit test case for following...
Please Sign up or sign in to vote.
8 Dec 2015
F-ES Sitecore
That code isn't really unit-testable. When you unit test you have to convert your code into services that are accessed via interfaces and it is those services\interfaces that you moq. So create an IMyData interface with a GetJobs method, then create a MyData class that implements this...
Please Sign up or sign in to vote.
14 Dec 2015
Raghuveer Kasyap
1 alternative  
Hi Guys,Please suggest me a best, flexible, open source Unit testing framework for testing the JavaScript (written in .js) using the Visual Studio Test Project.Thanks in advance.regards,Raghu
Please Sign up or sign in to vote.
14 Dec 2015
Suvendu Shekhar Giri
You may consider Chutzpah.Github link -https://github.com/mmanela/chutzpah[^]Article - Chutzpah – A JavaScript Test Runner[^]Features:1. Open Source2. Visual Studio Extension3. Command Line Utility4. Run test from Source file context menuetc.Hope, it helps :)
Please Sign up or sign in to vote.
11 Jan 2016
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...
Please Sign up or sign in to vote.
15 Feb 2016
Chandra Mohan BS
I want to configure the unit tests to run for a predefined set of data but do not want to define those in external database/file. Reason being - it's a simple data collection that would make sense to be visible right in the test .cs file. Is there any way you can configure the datasource to a...
Please Sign up or sign in to vote.
5 Mar 2016
lsarie
1 alternative  
Hi,I am working on unit test with MFC. My software is a SDI.I have 2 threads : the first one is the graphic thread and the second one a unit test procedure which reproduce a user behavior. It is working well when there isn't modal dialog, I use SendMessage (to simulate click on button,...
Please Sign up or sign in to vote.
5 Mar 2016
Serkan Onat
Your first attempt will not work because , you looking for a modal dialog , which has a style of WS_POPUPA popup window can not contain a style of WS_CHILDFolowing code will not return dialog template ID (for popup windows), it returns control ID for child windows (including dialog...
Please Sign up or sign in to vote.
4 Apr 2016
Raghuveer Kasyap
1 alternative  
Hi,I am working on a Project that involves testing a Simple SQL Query like, SELECT, INSERT, UPDATE AND DELETE.The VS 2010/ 2012 is the test environment. I know how to test a SP using MS unit Testing framework. But as per the requirement I need to test the above said SQL Commands /...
Please Sign up or sign in to vote.
4 Apr 2016
RickZeeland
You might try TSQLT - THE DATABASE UNIT TESTING FRAMEWORK FOR SQL SERVER, which allows you to implement unit tests in T-SQL.It is open source and you can find it here: tSQLt - Database Unit Testing for SQL Server[^]
Please Sign up or sign in to vote.
27 May 2016
m.r.m.40
2 alternatives  
Hi,I'm using AspNet.Mvc web application which I'd like to test it using 'ms unit test' here is the controller function which i'm testing:public ActionResult Delete(int id) Student studentToDelete = new Student() { ID = id }; db.Entry(studentToDelete).State =...
Please Sign up or sign in to vote.
25 May 2016
Muni Bhaskar
I had a private method and it returns a void return type and i had query which can thrown exception. i need to write a test which expects exceptionWhat I have tried:i tried dothrow(new exception("Exception")).when(mockdaoclass).method();any suggestions???
Please Sign up or sign in to vote.
27 May 2016
F-ES Sitecore
First of all, this isn't a unit test, a unit test requires no external resources and tests only your code's logic. Secondly all your test I trying to test is EntityFramework, but you should assume that MS test their own code so you don't have to. Thirdly your controller code is not unit...
Please Sign up or sign in to vote.
28 Aug 2016
yeleswarapu ramakrishna
1 alternative  
below is the method i tried to test but it fails for Employee.CurrentEmployee.IsManager this is a boolean value being fetched from a nested class which is dependent on the session so when i run unit test for this it fails cause there is no session created while i am running unit test so i tried...
Please Sign up or sign in to vote.
28 Aug 2016
FranzBe
you have some magic numbers there in your controller code. Why don't you swap this out in some extra class, thereby you get some interface you can mock against.e.g.void Main(){ var a = new PlanAuthorizationProvider(); var result = a.IsAuthorized(true, 387484); //result.Dump(); ...
Please Sign up or sign in to vote.
11 Oct 2016
Sandeep Londhe
1 alternative  
I am working on Android Since 2 years , I never find it needful to learn App Testing in my career yet. So I would like to ask my fellow developers, is it necessary to learn android app testing likeUnit TestIntegration TestOperational TestSystem TestIf yes, then please do let me...
Please Sign up or sign in to vote.
11 Oct 2016
Patrice T
Quote:Is it necessary to learn android app testing for android developer?There are 2 reasons why you don't need to learn app testing:- You are the only developer on earth that never make mistakes.- Since your app is malware, there is no need for testing anyway, bugs are secondary as long as...
Please Sign up or sign in to vote.
2 Aug 2018
user 3008
2 alternatives  
I have got the below set of code if (entity.InterpreterCostAuthorised && entity.InterpreterCostAuthorisedDate == null) { entity.InterpreterCostAuthorisedDate = DateTime.UtcNow; } else if (!entity.InterpreterCostAuthorised) ...
Please Sign up or sign in to vote.
29 Nov 2016
Ankit Rana
1 alternative  
While doing unit testing, i am not able to get collection back from dbset after add new entity in dbset, it throw an exception 'Collection was modified'Here is my code setup[TestMethod][TestCategory("Skill Category")]public void Create_Skill_Category(){ var category = new...
Please Sign up or sign in to vote.
29 Nov 2016
Ankit Rana
The error occurred in moq Dbset because I m not updating the reference of GetEnumerator after adding new Entity in DB set.Code : public class Utility { public static Mock> GenerateMockEntity(List entityList) where TEntity : class { var list = new...
Please Sign up or sign in to vote.
7 Feb 2017
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...
Please Sign up or sign in to vote.
20 Apr 2017
Vishal Pand3y
I'm trying to setup Unit Test in services using Moq and NUnit I tried Mocking context and DbSet like var mockSet = new Mock>(); var mockContext = new Mock(); mockContext.SetupGet(m => m.Student).Returns(mockSet.Object); but my services depends on other service...
Please Sign up or sign in to vote.
13 Jul 2017
User1454
1 alternative  
Hi all, I have a .net core application that use MS test tools for unit testing and works fine in windows using the commands 'dotnet test' and displays the failed and passed results. But now I am stuck up for linux platform. How can I do the same in linux platform.Whether publishing it for...
Please Sign up or sign in to vote.
27 Sep 2017
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...
Please Sign up or sign in to vote.
27 Sep 2017
Bernhard Hiller
Overall, that's a terribly bad code: PrintFunctionError requires a user to interact with the console. Whenever that function will be called within a Unit Test (or run on a Web Server, a Windows Service etc.), it will just hang. A return value is not meant to indicate if an exception happened or...
Please Sign up or sign in to vote.
8 Mar 2018
jimmyHuey
I have a function like following, this is a rudux to provide EstateList. import {render} from "react-dom"; import React from "react"; import {Provider} from "react-redux"; import store from "./Store"; import EstateList from "../estates/estateList/estateList"; function estateList() { ...
Please Sign up or sign in to vote.
2 Apr 2018
Jamie888
1 alternative  
Hi, may I know is there any tool/library/generator that i can refer to in order to generate general unit test method? For example, i have a method that goes to DB to retrieve data, i need to ensure that method does not return null. For traditionally way, i need to code a unit test to check for...
Please Sign up or sign in to vote.
4 Jun 2018
Anele Ngqandu
Hi I have method I want to test and I get this error Invoke or BeginInvoke cannot be called on a control until the window handle has been created. i understand this because of the form needs to run first but any alternatives? public partial class ImportForm : Form{ public ImportForm() ...
Please Sign up or sign in to vote.
15 Jun 2018
User 4180254
1 alternative  
Greetings. I have a method returning VOID and I have written below Unit test with "Microsoft.VisualStudio.TestTools.UnitTesting" for it. Is there any better alternative to do so? What I have tried: using (var uow = new UOW.SalesEntityUOW()) { try { uow.MyMethodCall(); // This...
Please Sign up or sign in to vote.
15 Jun 2018
Scyldshefing
I would agree that as presented the test does not test the void method. It does not even verify that an expected exception is thrown when a certain condition arises. All it does it verify that something runs and does not throw an exception. Void method can be tested but you will need to look at...
Please Sign up or sign in to vote.
17 Jun 2018
GregoryPres
1 alternative  
I wanted to help some of my student friends and explain the concept of TDD. As I don't have the time for it, I wanted to know if there's a faster/better way to learn the concept and basics of TDD for beginners. I know there are plenty of courses, blogs, guides. I'm interested to know how did...
Please Sign up or sign in to vote.
17 Jun 2018
Mehdi Gholam
You learn anything by doing it, it's that simple. As for TDD : 1) Write a test/usage code for what you want the output to be. 2) Implement the actual code to reach the output from a specified input, and make step 1 pass. 3) Repeat the above.
Please Sign up or sign in to vote.
6 Jul 2018
Agarwal1984
1 alternative  
Hello, When i am running my Unit Test project,so its getting error from mvc application" System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Web.HttpContext.Current.get returned null. " I have tried in MVC Application. Please help me. Thanks in...
Please Sign up or sign in to vote.
6 Jul 2018
F-ES Sitecore
You get an error but don't tell us what line it is on so I'm not sure what kind of help you are expecting. However from the error message it seems somewhere in the code you haven't posted you are using "System.Web.HttpContext.Current", however your unit test is running in the context of your...
Please Sign up or sign in to vote.
28 Aug 2018
Member 13784265
1 alternative  
since i am very beginner here i have been trying to test my c++ program.whenever i get into visualc++ -> Test i get these two "native unit test project" and "managed unit test project".but in c# i get "unit test project". What I have tried: How can i get "unit test project" option in c++ as...
Please Sign up or sign in to vote.
19 Dec 2018
Iris Shing
1 alternative  
I'm writing APIs using c#.Net Core One of my APIs is used to generate captcha then store to the session, I'm using Redis to store session here. And now I'm trying to write a unit test for the APIs. Cause the login API needed to pass captcha, so I need to get the captcha value from the session....
Please Sign up or sign in to vote.
19 Dec 2018
mehr.ah
In integration test you do not need to get a real value of captcha but in UI /Real test you need to take it but not from mock framework.
Please Sign up or sign in to vote.
1 Apr 2019
BillWoodruff
1. please explain what this means: "a solution that has 80% success" 2. in general you do not unit test private methods; after all, by definition they are only used from the public API 3. of course, the architecture of an app can be so screwed up that you can't isolate certain classes; as you...
Please Sign up or sign in to vote.
2 Apr 2019
F-ES Sitecore
The bad news is that your task is probably impossible. Unit testing isn't something you can retro-fit to an application, it has to be written with unit testing in mind. Trying to retro-fit unit testing to an app not designed for it will often lead to major refactoring of the code. To cover...
Please Sign up or sign in to vote.
2 Apr 2019
jerry.nothstine
You can access the private methods with reflection: MethodInfo myPrivateMethod = typeof(MyClassBeingTested).GetMethod( "PrivateMethodName", "BindingFlags.NonPublic | BindingFlags.Instance); myPrivateMethod.Invoke( instanceOfMyClassBeingTested, new object[] { parameter1,...
Please Sign up or sign in to vote.
14 May 2019
IlanGreen
1 alternative  
I need to mock objects and change method behavior in c++. The problem is that Gmock requires my methods to be virtual in order to inherit from them and change the behavior but I am not able to change my methods to virtual. What I have tried: I have tried Typemock Isolator++, it can access any...
Please Sign up or sign in to vote.
14 May 2019
Richard MacCutchan
Take your pick: List of unit testing frameworks - Wikipedia[^].
Please Sign up or sign in to vote.
23 May 2019
IlanGreen
1 alternative  
I have a method that i need to test all of its branches. I can't find a way to assert the or verify the test is correct because both branches have almost the same behavior. btw - I can't change the given code I have tried verifying End and Write are called but they are being called in both...
Please Sign up or sign in to vote.
23 May 2019
AnotherKen
It is unclear what you mean. Assert is used in C# in various ways as a method that can be invoked to empower code to use higher permissions than it would normally have or to test a variable and throw an exception if it contains an unexpected value. It may be that you are confusing people by...
Please Sign up or sign in to vote.
28 May 2019
user 3008
1 alternative  
In moq setup I am trying to assign the value of one of the argument to a string variable. Although I used callback but still the variable seems to have null value. What I have tried: I tried this Mock partialMockLunaService = new Mock(MockBehavior.Strict); ...
Please Sign up or sign in to vote.
28 May 2019
Gerry Schmitz
Only you know which parameters will work. c# - Setting a passed parameter to a specific value in Moq - Stack Overflow[^]
Please Sign up or sign in to vote.
20 Jun 2019
MAN CHUN LIEW
1 alternative  
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)) { ...
Please Sign up or sign in to vote.
20 Jun 2019
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. ...
Please Sign up or sign in to vote.
21 Oct 2019
Gerry Schmitz
Sum hash numbers. Or some "set" operations. Object.GetHashCode Method (System) | Microsoft Docs[^] Set Operations (C#) | Microsoft Docs[^]
Please Sign up or sign in to vote.
6 Jan 2020
Member 14708673
2 alternatives  
I have a finished project that I submitted yesterday to a client, and this morning he said that he'd like it if I implemented a few Unit Testing Frameworks into the project; Jest for Unit testing : integration of Jest [ Test Runner ] Enzyme [ Container UI Test ] Storybook [ Component UI Test ]...
Please Sign up or sign in to vote.
6 Jan 2020
Patrice T
Quote: I'm new to unit testing so I'm not quite sure how to use these Google is your friend : Unit testing - Wikipedia[^] Quote: and what to use these for It is used to check that your code gives expected results.
Please Sign up or sign in to vote.
6 Jan 2020
Dave Kreskowiak
If you didn't design your code with unit testing in mind, you've got a LOT of work to do to add that capability. You can't just a some uniting module and call it good. Your code has to be written to be testable, and that means writing your code against Interfaces. If you haven't done this, your...
Please Sign up or sign in to vote.
9 Mar 2020
Member 13958707
1 alternative  
I have a ssis package where it reads a folder with csv files and transform those files into sql server table. at the same time those csv files are moved to an archive folder. If there is any file with wrong extension or file format against the...
Please Sign up or sign in to vote.
16 Apr 2020
Member 14803912
1 alternative  
Please help me how do I write a test for the following controller without changing the program code ??? ***ProductController:*** [HttpPost] [ValidateAntiForgeryToken] public async Task CreateProductAsync(ProductDTO objProduct) { ...
Please Sign up or sign in to vote.
16 Apr 2020
F-ES Sitecore
You can't, if you want your code to be unit testable you have to write it with unit testing in mind.
Please Sign up or sign in to vote.
19 Apr 2020
Member 13081540
1 alternative  
am working with Microsoft.AspNetCore.Identity.UserManager and I'm trying to mock the creation of a new user. In fact, it does create a new user with username, email etc. but the password hash property is still null. This is how I set up mock...
Please Sign up or sign in to vote.
19 Apr 2020
Garth J Lancaster
Are you under the premise the PasswordHasher should be automatically called ? I did some research and wasn't convinced - I would have thought you'd need ApplicationUser user = _userManager.Users...; user.PasswordHash =...
Please Sign up or sign in to vote.
23 Jun 2020
Member 14686752
1 alternative  
I have written some unit test cases using Gtest framework. If I am trying to test the class whose constructor is making the object of another class, GTest is crashing. Code is as follows: User1.cpp class User1 { public: User1()...
Please Sign up or sign in to vote.
24 Aug 2020
Member 14922145
when I tried to run and generate a code coverage report for multiple dll's that code is not working but same code is working for single dll getting error in the following code ---------------------------------------------------------------- ...
Please Sign up or sign in to vote.
1 Nov 2020
Shayalp1
2 alternatives  
Hi, I'm actually new to programming, I had an assignment to create a single screen game and now I have to conduct tests on it. I'm completely lost as to how to conduct the test in Visual Studio. Can anyone please assist me, I've been stuck on...
Please Sign up or sign in to vote.
28 Oct 2020
BillWoodruff
The Unity Test Framework package (formerly the “Unity Test Runner”) is a tool that allows you to test your code in both Edit mode and Play mode, and also on target platforms such as Standalone, Android, or iOS . For more information on other...
Please Sign up or sign in to vote.
28 Apr 2021
Member 15175929
I have created a share button and on clicking that you have share app link option where you can share in various app. So I just wanted to test this sharing app. I am new in the android and till now I did not got any good material related to this...
Please Sign up or sign in to vote.
21 Jan 2014
Ashley Davis
Documents my experiment building a flowchart with web technologies.
Please Sign up or sign in to vote.
11 Mar 2020
Vassili Kravtchenko-Berejnoi
Use of a narrow-focus strategy in test-driven-development
Please Sign up or sign in to vote.
19 Sep 2012
David Bywaters
Two approaches for unit testing Entity Framework
Please Sign up or sign in to vote.
8 May 2014
Halil ibrahim Kalkan
An implementation of dependency injection, repository and unit of work patterns using Castle Windsor and NHibernate.
Please Sign up or sign in to vote.
27 Dec 2012
WebMaster
Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with clean & simple API.
Please Sign up or sign in to vote.
20 Jun 2012
Henning Dieterichs
This article introduces a library for handling units of measure.
Please Sign up or sign in to vote.
21 Jan 2013
Simeon Sheye
How to manage state and simulate behavior against the system under test.
Please Sign up or sign in to vote.
16 Dec 2013
Seckin Tozlu
How to create a comprehensive test suite for your API
Please Sign up or sign in to vote.
30 May 2016
Evgeny N
Combinatorial tests are helpful to cover a lot of various input data combinations, but their out-of-the box support in testing frameworks can easily bloat your continuous integration server times. Not necessarily...
Please Sign up or sign in to vote.
5 Jun 2013
Lukasz Szyrmer
Use cost of market delay and your learning costs to figure out whether TDD, or its alternatives, makes sense for you
Please Sign up or sign in to vote.
9 Dec 2013
Pete O'Hanlon
While we are all familiar with testing standard interface implementations, actually testing Lazy imports can be trickier if you don't follow this trick.
Please Sign up or sign in to vote.
20 Nov 2016
Sibeesh Passion
In this post we will see how we can write unit test cases for our WCF Service with a framework called NUnit. We will also be covering how to mock our dependencies in our test, here we wil be using Rhino Mocks. I am going to use Visual Studio 2015 for the development. I hope […]
Please Sign up or sign in to vote.
5 Jan 2020
Paulo Zemek
I partially agree with the basic idea, but it fails when we need to deal with an issue no unit-test caught and the good developers and code-reviewers simply can't understand what's going on.
Please Sign up or sign in to vote.
11 Oct 2013
ASP.NET Community
ASP.NET MVC: How to start Unit TestingWhy Unit Testing?Why should you write Unit Tests? Here are some points which are mostly mentioned if
Please Sign up or sign in to vote.
8 Nov 2015
Michael Pan
Presenting techniques for effective usage of Google unit test frameworks in embedded environment.