Execute Unit Tests using MsBuild command line - c#

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.

Related

How to auto run a dotnet command when opening a solution in visual studio

I am interested to run dotnet watch test when opening a solution with my unit tests in visual studio 2017. Is there a way to run that just after the solution is open without doing it manually?
Visual Studio Task Runner can run any arbitrary CMD command when a project/solution is opened.
Prerequisites: Command Task Runner extention.
Add Foo.cmd with a target command to your project having dotnet watch package installed. It could have one line of code:
dotnet watch run
Make sure the file is properly encoded to UTF-8 without BOM.
After Command Task Runner extention install, Add to Task Runner option should be accessible from context menu of *.cmd files. Press it and choose per-project level. As a result, commands.json should appear in the project.
Go to VS View -> Other Windows -> Task Runner Explorer. Set up the binding for the Foo command in the context menu: Bindings -> Project Open (the window refresh could help to see a recently added command).
Re-open the solution and check a command execution result in Task Runner Explorer.
How it could look:

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

how to run an mstest dll from command line

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

build .net solution from batch file

I have a solution file comprising of 15 projects using a few third party dll references. I want to be able to build the solution from a batch file. What is the best way to do this?
Thanks
Run msbuild - for example:
msbuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU"
One of the simplest ways is to execute msbuild with the solution file as input:
#echo off
call %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe path\to\solution.sln
If this is done in a Visual Studio command prompt you can skip the path to msbuild.exe.
One way to get started is to open the project in Visual Studio and select Build | Rebuild Solution. Then go to View | Output. In the output window select "Build" in the Show Options From dropdown. This will display the commands that Visual Studio is using to build the project. You can paste those into a batch file, and read or modify them as desired.
If you want to maintain both Debug and Release versions of your application, then you will want to select the correct configuration and then follow the above steps for each version.

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