Running tests as a different user in Visual Studio - visual-studio

I have a program that needs to run as a separate NT user to connect to a SQL Server databases. For running a program itself, this isn't a big deal as I can just right click on it in windows explorer and select run as. Is there any way to run my tests as a different user as well? (it would be nice if I could do so in Visual Studio)
Update: As of right now, I'm just unit testing using the integrated unit testing framework in Visual Studio 2008 Pro. I'm running them just using the "run all tests in current solution" menu option.

There's a command line program "runas", which you can use to run your tests as long as they are standalone programs. I'm not sure how exactly to integreate it with your tests, as I may need a bit more information on how you run them.
This method will ask you to enter your password.

You could absract and mock the mechanism that determines the current user. This would allow you test as anyone.

Related

How do I save test results from Test Explorer in Visual Studio 2017?

I have an issue with Visual Studio 2017. I generally run a set of tests locally on my own computer using Test Explorer and using Microsoft's own Unit Testing tools in the Visual Studio library. This can take quite sometime. Problem is, if I close visual studio at any point, the results of these tests are lost forever: the pass, the fail, the output, everything.
I need a way to save the results of my tests in case this happens. I'd love it if VS didn't just wipe my test results like this.
I have to run many tests in different windows, using the command prompt to do this is incredibly laborious.
You can use the command line tool VSTest.Console.exe command-line options and save the output to file using /Logger: option.
It can be found under
(Visual-Studio-Directory)\(Version-Year)\Common7\IDE\Extensions\TestPlatform
Sample:
vstest.console.exe "C:\TestProjectFolder\TestProject.dll" --logger:trx
You can configure trace logging using a test settings file, documented here.

Microsoft Visual Studio 2015 Installer custom button

I need to create an installer for a web project in VS with Microsoft Visual Studio 2015 Installer Projects where the user who performs the installation the installer asked for the data of connection to the database with two textbox, in these 2 textBox i need the user through a "Test Connection" button to verify this connection before the user continues to the next step of the installation.
How can I do this button in the installer and apply the logic to validate if the connections that the user entered in the installer are correct?
looks like
thank you very much I am new in this
am using Visual Studio 2015 Proffessional
There's no support in Visual Studio setup projects for validating user input in that UI sequence. In other words VS setup projects don't support custom action calls from the UI sequence (although other tools do).
It's common for this type of thing to be delegated to the setup, but in practice it often works better to just let the app install and then have the app do the configuration and any testing of IP addresses. After all I doubt that the install needs that IP to be up and running, it's the app that needs it.
Also, there may be a need for the IP to change, or the user and password. And if you actually entered a user name and password into that dialog there is no support in VS setups for securing that data, therefore the password is exposed.
I agree with Phil, but I was just thinking: if there is no application to launch (if you are deploying a web app), then perhaps you can just make yourself a little launcher.exe that pushes a command line to msiexec.exe (Windows Installer Installation Engine) with the required data and then kick the install off in silent mode and avoiding all the setup GUI issues and complexities?
So your launcher EXE would do all the GUI (familiar territory), and you just run the setup itself in silent mode, pushing a command line along these lines:
msiexec.exe /i Setup.msi /QN /L*V "C:\msilog.log" USER="User" PASSWORD="Pass" IP="0.0.0.0" REBOOT=ReallySuppress
I am not really familiar with this project type - I guess a launcher.exe conflicts with the pre-requisite setup.exe launcher that is already there for installer projects? The one which downloads and installs pre-requisites?
Perhaps you could encrypt the password in your launcher.exe and add a custom action in deferred mode in the MSI which will decrypt the configuration data and write it somewhere. Ideally you would use NT authentication I guess - avoiding the whole password / username issue.
Overall I would recommend using WiX instead of these installer projects. Though complicated, WiX is fully capable of all kinds of features - even if GUI is always complex when it comes to MSI. UPDATE: I should also add that WiX features its own launcher / bootstrapper / chainer feature called Burn. It is basically supporting the launching of MSI files in silent mode from a GUI you create yourself (or you use the default one) - much in the way I described above (with far more additional features). Maybe have a look at the "Building Installation Package Bundles" section.

How to run tests while debugging

I've been using ReSharper test runner in Visual Studio for quite a while, and there is one thing about it that I can't figure out.
I used to have some integrational tests in my solution that performed web requests to my local web server. I used to be able to launch my web application in debug mode, then launch a test with Resharper test runner within the same Visual Studio instance (that was currently running a debug session), and the test would run normally. The breakpoints in my application were hit, and I was able to debug the requests sent from the test.
However, when I was trying to do the same thing for a new project, the tests fail to launch. When I run any test, Visual Studio displays a modal window asking Do you want to stop debugging?. Why am I unable to run tests while having an active debugging session anymore? What does the ability to do this depend on? Visual Studio version? Resharper version? Unit testing framework (I'm currently using MSTest)?
I think I've seen this behavior before, it seemed to be driven by the fact that Resharper was feeling the need to always build my project/solution before running tests.
Try changing the Build Policy to Never (at first at least) from the Unit Test Sessions window:

How do I debug a .net application as a specific user?

I'm creating a WinForms application in Visual Studio 2008.
I want to run my application in the debugger and I want the application to run as a user other than the user running Visual Studio. What is the best way to do this?
If you have access to an OS that lets you have multiple terminal server sessions open, then simply open a new terminal server session as that user. With an administrator account running Visual Studio you should be able to debug the process in the other session.
You could add calls to your app to login as the desired user, but that isn't ideal since the environment is clearly not identical to the experience of running as that user.
Otherwise I think you need to look at remote debugging scenarios where VS is installed on a separate box.

How can I get started using Nunit in my Visual Studio project?

I want to start using Nunit (finally), I am using Visual Studio 2008.
Is it as simple as importing Nunit into my test project?
I remember seeing a GUI for NUnit, does that do the exact same thing that a separate test project would do, except show you the pass/fail visually?
I like to add a link to NUnit in my external tools.
Under Tools->External Tools add NUnit
Title: &NUnit
Command: <path to nunit>
Arguments $(ProjectFileName) /run
Initial directory: $(ProjectDir)
After that you can quickly run it by compiling then hitting alt-t + n
Yes, that's basically it. Personally I find the unit test runner which comes with ReSharper to be excellent - and the tool itself is well worth the licence feel. Alternatively there's TestDriven.NET.
Having a test project which runs nunit-gui or nunit-console separately is all very well, but you really want the whole unit testing experience to be as seamless as possible. The easier it is to write and run tests, the more likely you are to do it - which is a very good thing. Don't underestimate the gradual build-up of frustration due to a slightly poorer user experience, flipping between windows etc.
NUnit is something that isn't inside Visual Studio 2008. It does have a console OR a graphical user interface (gui) that can be run both outside VS2008 OR can be attached to the process of VS2008 for debugging.
If you do want something inside VS2008 you need to have a third party pluging like ReSharper.
Edit: This has been answered in the past (not for VS2008 specificly but still relevant)
I've used TestDriven.NET with VS2005, and it has changed how I develop and test code.
You can run all of the tests on any class, module, project, or solution. You can also run a test in the debugger, which is tremendously useful to diagnose and fix issues when they crop up.
The GUI is nice, but if you run your tests often, you'll probably abandon it for a faster/integrated runner.
In any case, you have some options on how to run your tests:
NUnit.Gui.Exe -- you can run this & select your test project dll to run the tests. While it is open it will refresh when you build, so you can ALT-TAB to it & re-run your tets. Another technique I've seen is to set this application as the startup program for your test project. Then set your test project as the startup project and push F5.
Download & use TestDriven.net. This is fast and lets you run tests from a right click menu, while you're sitting on a test or at a node in the solution explorer. This is what I use mostly. I have it mapped to CTRL+T for quick access.
Resharper has a test runner as well. This gives you the GUI with red/green lights inside of visual studio. It also gives you a little icon next to each of your tests to quickly run them.
You can use the plugin NUnitForVS that is available here: http://www.codeplex.com/NUnitForVS
This integrates the test running and results in your VS 2008 IDE. We've been using it for a couple of months and it's working well for us.
You should also remember that with VS 2008 professional you can use the MS Unit testing tool that was previously only available in the team versions.
You can run it as external program, but as for me it is not very nice. I like, when test starts within the VS. So, if you have ReSharpe you can go to Tools -> Options -> Environment -> Keyboard and set the hot key for ReSharper_UnitTest_ContextRun. I set it to Ctrl + t.
I attach my nunit console program to the Post-build event so every time I build my project the tests are run without the need for third party tools (apart from NUnit). I'm using Visual Studio 2010, but I am pretty sure you can achieve the same behaviour in Visual Studio 2008.
To do this:
Open the project's properties window (the project containing the tests)
In the Post-build event command line add the line:
"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe" "$(TargetDir)$(TargetFileName)"
Build the project and the output should be written to the Ouptput window (Build). It's important to choose the x86 version of the console runner.

Resources