I have created a program in Visual Studio 2017, and I just noticed now that I forgot to add unit testing when creating it, and I am too far gone to start over.
How can I solve this problem?
You should be able to right-click on the solution, and Add Project, then Unit Test Project. Unless you're not using MSTest, then add a new project and choose class library.
Related
How can I unit test a Windows 10 app in Visual Studio 2015?
I created a Blank App Universal Windows project and added a new Unit Test Project to the solution, but when I try to add a reference to my UWP app in the Test Project, I get an error saying 'Unable to add a reference to project "Project Name"'.
Right click on your solution and choose Add > New Project. Then select Unit Test App (Windows Universal). Make sure that you don't select Unit Test Library or Unit Test Project. It must be the Universal one. This should generate a base class for you to work with.
You'll probably then want to add a reference to your main project. To do this, right click on your test project and select Add > Reference and then choose your main project. You should now be able to create classes from your main project to test.
I can understand the confusion - the Visual Studio team is not consistent in there otherwise fine project hierarchy decisions.
Normal approach was to place Test projects under Test. For reasons unknown, they decided to place the Unit Test App (Universal Windows) directly under Windows -> Universal and hereby bypassing common sense.
In summary; Test projects for Windows -> Classic Desktop and Web is placed under Test. Test projects for Windows -> Universal is placed under Windows -> Universal.
Try RT-Clicking on a function name & see if there is a "Create Unit Tests" option on the context menu. For some reason adding a new unit test project is buggy, but the context menu worked for me.
I am using VS2012 (v110)
I create a simple dll application with only 1 function and a test project to test the dll function. I set up both projects to be debug builds for win32 and tried Clean and Rebuild both projects but I don't see any test to be run on the test Explorer windows.
I also reference Dll project in the test project already.
Why isn't there anything shown in Test Explorer windows?
Actually MSTest doesn't work with simple class library projects.
You will have to create a unit test project and place your tests there.
If you use other testing frameworks like NUnit, then you can use plain class library. You can then use NUnit to run the tests outside VS, or use tools like ReSharper to run those tests inside VS
It seems you have used some test frameworks other that MSTest. If you want to use Test Explorer for some other frameworks you should install its runner too. for instance NUnit needs to install its test adapter as and extension in VS.NET
see here for more.
You should be able to modify an existing class library project to get mstest to recognize it as a test project by modifying the ProjectTypeGuids in the .csproj file as detailed in this answer How to get VS2010 to recognize my mstests generated by SpecFlow? (Look for the answer that lists the specific guids and not the currently accepted answer which says to just create a new project.)
Have had a simular problem. Solved it. I have been adding tests project to my VS 2012 solution and tests were not appearing in Test Explorer. Problem was that test project was located in IIS inetpub\wwwroot folder which didn't have windows user rights to modify it. Adding solution folder Windows user rights to modify it solved issue. Tests are now visible in test explorer and able to be debugged. I assume that vstest.discoveryengine.exe process with is run by windows user was not having access to test project files
I have made a project in visual studio and also implemented unit testing.
The code working fine with the unit testing.
Now I have a doubt that is it possible to implement unit testing outside the visual studio environment such that I only use the exe generated by my project and test it for multiple cases?
I am looking for an option which can utilise my current unit testing implementation
I am new to unit testing, so any help would be appreciated
thanks in advance
Installing MSTest without Visual Studio is not quite trivial thing. This tool was very useful to me in this regard.
Originated from here
You can use outside library like NUnit, there is manager to run your test
If from outside, you mean outside of Visual Studio IDE, then you can use mstest.exe which VS internally uses. This is stand alone in sense, that host doesn't need VS installed. Thus e.g. a build system can call this and do unit test towards the end of build.
If you are using the Microsoft test framework, you can run MSTest.exe from the command line.
If you set up your test classes as per this SO answer then you can run them in either MSTest or NUnit, based on a compilation option. Hope this helps!
Using both MSTest and NUnit?
I have a visual studio project. I later added a .cs file for testing and have added the appropriate 'using' statements and [Test] and [Testfixture] attributes. When I open the nunit gui application, however, it only accepts .dll, .exe, and .nunit files. I was wondering what exact steps I need to take to execute the tests I wrote. Is it possible to do so directly in visual studio?
You should add the NUnit dll as a reference on your project.
JetBrains' Resharper is able to run the tests inside Visual Studio. Read more about Resharpers unittesting here. JetBrains has also developed a line coverage tool: dotCover.
Right now, Resharper is the best solution.
Test Driven .Net is the best free solution I know of.
Visual Studio 11 will finally allow for 3rd part testing framework plugins.
I am working on a class library (DLL) project in Visual Studio 2008; programming in C#. In order to test my DLL I just created a second project that is a console application and in that project I can reference the first and run tests. Is there a simpler way of doing this? Can I just create another file within my class library project that has the tests in it and then somehow tell Visual Studio to run that file?
I know one way would be to add a text file to my project and then write my test code in JScript. Then in the Project settings on the debug menu I can tell it to Start External Program (JScript). Then, the name of my test file, test.js, goes in the Command Line Arguments box. But, I am wondering if there is a way to do it using C# code instead of JScript?
You could add a testing project to your current solution, then set that project as the startup project. Then, hitting F5 on your class library project will start your testing project.
Take a look at NUnit or other similar unit testing framework.
The "Team Developer" and "Team Suite" flavors of Visual Studio already have Microsoft's unit testing framework built in.
Create a unit test project for the class library by using the right-click "Create Unit Tests" in a class/method in the library. I would recommend downloading TestDriven.NET and using the right-click test runner in it.
Are you talking about unit tests? You can use something like nUnit or the built in testing framework that comes with Visual Studio. The simplest tests just require you to add some attributes to your test fixture and make an assertion like obj1 == obj2.
Checking out something like Test-Driven Development (TDD), Domain-Driven Development (DDD) or Behavioral-Driven Development (BDD) may be beneficial. I like to use nUnit with nBehave, myself.