在Visual Studio中以不同用户身份运行测试

时间:2022-03-02 15:01:21

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)

我有一个程序需要作为一个单独的NT用户运行连接到SQL Server数据库。对于运行程序本身,这不是什么大问题,因为我可以在Windows资源管理器中右键单击它并选择运行为。有没有办法以不同的用户身份运行我的测试? (如果我能在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.

更新:截至目前,我只是使用Visual Studio 2008 Pro中的集成单元测试框架进行单元测试。我正在使用“在当前解决方案中运行所有测试”菜单选项来运行它们。

2 个解决方案

#1


1  

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.

有一个命令行程序“runas”,只要它们是独立程序,您就可以使用它来运行测试。我不确定如何将它与测试完全整合,因为我可能需要更多关于如何运行它们的信息。

This method will ask you to enter your password.

此方法将要求您输入密码。

#2


1  

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

您可以抽象并模拟确定当前用户的机制。这将允许您像任何人一样进行测试。

#1


1  

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.

有一个命令行程序“runas”,只要它们是独立程序,您就可以使用它来运行测试。我不确定如何将它与测试完全整合,因为我可能需要更多关于如何运行它们的信息。

This method will ask you to enter your password.

此方法将要求您输入密码。

#2


1  

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

您可以抽象并模拟确定当前用户的机制。这将允许您像任何人一样进行测试。