how to run an mstest dll from command line - c#

anybody knows how to run unit test dlls built using mstest from the command line, without running VS
considering that on the machine there is .net 4.0 and VS2010 installed

I haven't done it myself, but I'd imagine that using the mstest command line is the way forward... if you've already tried that and had problems, please give more details.
mstest /testcontainer:path\to\tests.dll
EDIT: As noted in comments, you should either do this after putting the right directories on the path, or include the full path to mstest.exe.

Quick Answer :
Examples
You must use the /testcontainer option together with the /category option to select which tests in which categories to run. The following command, for example, is run in the solution folder and runs the tests that are in both the Priority 1 and ShoppingCart categories.:
MSTest /testcontainer: testproject2\bin\debug\testproject2.dll /category:"Priority1&ShoppingCart"
Note
Because the test assembly file resides in a different folder, a relative path is necessary,
If you are using test lists, it is best to use the /testmetadata option together with the /testlist option. The following command, for example, is run in the solution folder. Because the test metadata file also resides in that folder, no path is necessary:
MSTest /testmetadata:Bank.vsmdi /testlist:balancetests
Detailed :
To run tests from the command line
1.
Open a Visual Studio command prompt.
To do this, click Start, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio Command Prompt (2010).
By default, the Visual Studio command prompt opens to the following folder:
:\Program Files\Microsoft Visual Studio 10.0\VC
Note
To change the folder to which the command prompt window opens by default, click Start, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, right-click Visual Studio Command Prompt (2010), and then click Properties. In the Visual Studio Command Prompt (2010) Properties dialog box, you can change the path to the default folder in the Start in box.
2.
Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.
To identify your solution folder, first identify the Visual Studio Projects folder. To do this, click Options on the Tools menu in Visual Studio, and then click Projects and Solutions. Under Visual Studio projects location, you see a path such as the following:
:\Documents and Settings\\My Documents\Visual Studio\Projects
Your solution folder is typically a child of this Projects folder, such as the Bank folder in the following example:
:\Documents and Settings\\My Documents\Visual Studio\Projects\Bank
3.
Run the MSTest.exe program.
When you run MSTest.exe, you must specify either a test metadata file or a test container, using either the /testmetadata option or the /testcontainer option, respectively. You use the /testmetadata option only once, to indicate one test metadata file. You can use the /testcontainer option multiple times, to indicate multiple test containers.
If necessary, include the path to the folder in which the metadata file or test container resides. Test metadata files reside in the solution folder.
Depending on the test type, test containers are XML files, assemblies built from test projects, or other files that reside in the folders of a test project.
Source: http://msdn.microsoft.com/en-us/library/ms182487(v=vs.100).aspx

Try this
mstest.exe /testcontainer:c:\projects\MyTests\Sampe.Tests.dll

Related

Run button missing for c# in VSCODE

When I am using python in Visual Studio Code, I have the run button at the top right, however, when I am in a c# file, the run button is not there.
Why is that, and how can I fix it?
Since VS Code is a tool built with C# in mind, having the Run hidden is not a disadvantage but rather to dedicate a complete UI for Running and Debugging your C# code. The Run and Debug UI which you can access from the left menu gives your this capability with comprehensive tools to help you debug.
Activating this tool to run correctly involves two setups, one-time setup and a per-project setup (Don't let this intimidate you, it is just a click of a button)
First Time Setup
1. Install .NET command line tools
Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: https://dotnet.microsoft.com/download
2. Install C# Extension for VS Code
In the extensions tab, enter C# in the search box and press Enter. Select the extension from Microsoft and click on Install. If you have previously installed the C# extension, make sure that you have a recent version.
3. Wait for download of platform-specific files
The first time that C# code is opened in VS Code, the extension will download the platform-specific files needed for debugging and editing. Debugging and editor features will not work until these steps finish.
Once Per Project
1. Get a project
You can start from scratch by creating an empty console project with dotnet new. Begin by opening the terminal in Visual Studio Code (View->Integrated Terminal) or CTRL+` and type these commands:
cd ~
mkdir MyApplication
cd MyApplication
dotnet new console
2. Open the directory in VS Code
Go to File->Open Folder (File->Open on macOS) and open the directory in Visual Studio Code. If this is the first time that the C# extension has been activated, it will now download additional platform-specific dependencies.
3. Add VS Code configuration files to the workspace
VS Code needs to be configured so it understands how to build your project and debug it. For this there are two files which need to be added -- .vscode/tasks.json and .vscode/launch.json.
Tasks.json is used to configure what command line command is executed to build your project, and launch.json configures the type of debugger you want to use, and what program should be run under that debugger.
Launch.json configures VS Code to run the build task from tasks.json so that your program is automatically up-to-date each time you go to debug it.
If you open the folder containing your project, the C# extension can automatically generate these files for you if you have a basic project. When you open a project and the C# extension is installed, you should see the following prompt in VS Code:
Clicking Yes when you see this prompt is all that you really have to do when you open a new dotnet project. If the files are there already you won't be prompted.
Clicking Yes on this prompt should add these resources. Should you need to add those resources manually please check the reference link below.
4. Start debugging
Your project is now all set. Set a breakpoint or two where you want to stop, click the debugger play button (or press F5) and you are off.
Reference Link: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md
try pressing f5, should do the same thing as the run button

Where is the Visual Studio 'Test Explorer' Output located? Is it a saved file?

I'm using SpecFlow for unit testing in Visual Studio 2013, and when I run tests from the Test Explorer window, there is a link to an Output which shows anything written to the console during the test.
When right-clicking the tab, I don't have the option to Open Containing Folder like I do with other project files.
Is this a file that's being saved somewhere? Can I access it somewhere, or should I manually write the code to save it to a known location?
After digging around a bit I couldn't find a way to actually view the results from the test explorer window run. So the best I can do is give you an alternative.
What you will want to do is run your test using a program called vstest.console.exe, this works almost exactly the same way as running from VS. You can find it under
C:\Program Files(x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsft\TestWindow\vstest.console.exe
run this from your cmd/terminal and set it up as you would like. You can enable logging, files are saved under the the TestResults folder in the same folder listed above, and you should be able to see your results. An example test run would look like:
vstest.console.exe D:\(Path To my Test)\(My Tests dll file).dll /Settings:D:(Path tO my Tests)\(My Test settings file).testsettings /logger:trx

Changing test run results directory in CodedUI or moving results files

I am working with Coded UI Test Projects in Visual Studio 2012 Premium, and running my tests from Test Explorer. I would like to know if there is a form of changing the default directory for the test run files, because TestRunResultsDirectory property is readonly. Maybe it would be possible to move my files after executing the whole test?
Not 100% on how to change the output directory in VS IDE, but you can do so from the VS Command Prompt with the argument /resultsfile:[file name]. However, this only affects the results that are created when the test is run from the command line, of course.
However, you can find the result files at C:\users[your username]\AppData\Local\Temp\UITestLogs, if you wanted to simply manually move them after the fact.

Execute Unit Tests using MsBuild command line

I use scripting for this:
"%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"
get $/DmlOnDemmand /recursive /force /noprompt
And I build solution .sln
call %msBuildDir%\msbuild %solutionName% /t:Rebuild /p:Configuration=%buildType%
Now, I would like execute all Unit Tests and check all is OK.
How can I execute unit tests of .csproj projects of a solution from the command line using a build tool like MSBuild?
Look at VSTest.Console.EXE they added this for CodedUI tests. Seems to have more functionality.
https://msdn.microsoft.com/en-us/library/jj155800.aspx
in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow directory.
I inserted a Test-Project in the Solution.
Every build a library the test depends on is changed the solution updates the Test-Project. The Test is automaticaly run after each "Test-Project" change with the Post-Build option.
The result from the Test is directly shown in the buildlog.

why no output when use command line to build VS setup project?

I have installed Visual Studio 2008 on our build machine because we want to build the setup project to create MSI installer for our C# application.
From IDE, it works fine. The installer is created as expected.
Switch to command line, with the follow command the process finished without any error but there is no output (no installer created)
DevEnv.exe .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
change the /build to /deploy to /rebuild have no difference (no installer created)
I am doing anything wrong?
I just fought with a similar issue, where I'd run the devenv.exe and get no feedback and no output, even with the /Log flag. This is the exact same call I'd use in 2005, and it worked like a charm. But then I found a devenv.com in the same folder, so I tried that, and it ran as expected. I don't know the difference between the .com and .exe versions, but you might try that.
I think the problem is that you are running DevEnv.exe and not DevEnv.com.
This should output to the console.
DevEnv .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
Try building the solution file instead of the vdproj file in your command line statement
There must be at least one project in the solution that form the output of the installer project. These will need to be built as well.
Interesting question. I thought this would be pretty easy as well. I was able to easily do a release build by opening a VS2008 command prompt in the folder with my vdproj and running:
devenv SomeName.vdproj /build
But release was a lot trickier. After a few failed attempts on my own, this guy showed the way. For some reason, the fully qualified path to the sln and the vdproj seemed to do the trick (again I was in a VS2008 command prompt but this time I was in the SLN folder):
devenv "C:\SomePath\SomeSlnName.sln"
/rebuild Debug /project
"C:\SomePath\ProjectFolder\SomeProjectName.vdproj"
/projectconfig Debug
It doesn't make sense to create an installer for the Debug build, you always want the Release build.
If that's really necessary then open the .vdproj in Visual Studio, Build + Configuration Manager and tick the Build checkbox for the Debug configuration. Beware that this property is stored in the .sln file, not the .vdproj file so click File + Save All to let VS write the solution file.

Categories