Visual Studio에서 디버그 모드로 NUnit을 어떻게 실행합니까?
나는 최근에 내가 일하고있는 약간의 C #을위한 테스트 프레임 워크를 구축 해왔다. 구성 요소를 테스트하기 위해 NUnit을 설정하고 작업 공간 내에 새 프로젝트가 있습니다. Nunit (v2.4)에서 단위 테스트를로드하면 모두 잘 작동하지만 디버그 모드에서 실행하고 일부 중단 점을 설정하는 것이 실제로 유용한 지점에 도달했습니다.
나는 테스트 프로젝트의 '디버그'속성을 변경하도록 제안하는 여러 가이드의 제안을 시도했습니다.
Start external program: C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe
Command line arguments: /assembly: <full-path-to-solution>\TestDSP\bin\Debug\TestDSP.dll
콘솔 버전을 사용하고 있지만 GUI 호출도 시도했습니다. 디버깅을 시도하고 시작할 때 동일한 오류가 발생합니다.
Cannot start test project 'TestDSP' because the project does not contain any tests.
이것은 일반적으로 \ DSP.nunit을 Nunit GUI에로드하고 테스트가 개최되는 곳입니까?
VS가 자체 테스트 프레임 워크를 실행하고 싶어하고 NUnit 테스트를 찾지 못하는 이유가 문제라고 생각하기 시작했습니다.
편집 : 테스트 픽스처에 대해 묻는 사람들에게는 TestDSP 프로젝트의 .cs 파일 중 하나가 대략 다음과 같습니다.
namespace Some.TestNamespace
{
// Testing framework includes
using NUnit.Framework;
[TestFixture]
public class FirFilterTest
{
[Test]
public void Test01_ConstructorTest()
{
...some tests...
}
}
}
... C #과 NUnit 테스트 프레임 워크에 익숙하지 않으므로 중요한 정보를 놓친 것이 가능합니다. ;-)
최종 해결책 : 큰 문제는 내가 사용한 프로젝트였습니다. 당신이 선택하면 Other Languages -> Visual C# -> Test -> Test Project
프로젝트 유형을 선택할 때 ..., Visual Studio를 시도하고 내가 말할 수까지로로 자신의 테스트 프레임 워크를 사용합니다. 당신은 선택해야 정상적인 대신 C의 # 클래스 라이브러리 프로젝트를하고 나의 선택 대답의 지침 작동합니다.
나는 / assembly 플래그없이 Jon을 시도하는 것과 동일한 기술을 사용합니다.
Start External Program: C:\Program Files\NUnit 2.4.8\bin\nunit.exe
Command line arguments: "<path>\bin\Debug\Quotes.Domain.Tests.dll"
TestDSP.dll에 모든 TestFixture가 포함되어 있습니까?
테스트 프로젝트가 솔루션의 시작 프로젝트가 아니기 때문에 테스트 프로젝트를 마우스 오른쪽 단추로 클릭하고 디버그-> 새 인스턴스 시작을 선택하여 테스트를 실행합니다.
NUnit 테스트를 디버깅해야하는 경우 nunit-agent.exe
"Debug | Attach to Process"를 사용하여 NUnit GUI 응용 프로그램에 연결하고 GUI에서 테스트를 실행하면됩니다. 내 테스트 (또는 테스트중인 코드)의 중단 점이 발생합니다. 나는 당신의 질문을 오해하고 있습니까, 아니면 당신을 위해 효과가 있습니까?
다음과 같은 줄을 제거하십시오.
<ProjectTypeGuids>
{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
프로젝트 파일에서. 이 줄은 기본적으로 VS.Net에 테스트 프로젝트임을 알려주므로 "테스트 프로젝트를 시작할 수 없습니다"입니다. 참고로 여기에서 첫 번째 Guid는 "테스트입니다"라고 말하고 두 번째 Guid는 "It is the C #"입니다. 해당 가이드에 대한 정보는 http://www.mztools.com/Articles/2008/MZ2008017.aspx를 참조하십시오.
@Justin이 제공 한 답변 외에도 NUnit 2.6에 대한 자세한 내용이 있습니다.
NUnit 2.6을 사용하여 에이전트가 아닌 nunit.exe 또는 nunit-console.exe에 연결하십시오. @Justin이 언급 한 구성은 약간 다릅니다. 아래는 nunit.exe.config의 예입니다 (nunit-console.exe.config와 동일).
<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- Comment out the next line to force use of .NET 4.0 -->
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0.30319" />
</startup>
.NET 4 테스트 프로젝트의 경우 중단 점을 맞추려면 주석에서 제안한대로 v2.0 줄을 주석 처리하거나 제거해야합니다. 일단 그렇게하면 .NET 4.0 테스트 프로젝트를 디버깅 할 수있었습니다.
If you are using NUnit 2.4 or newer you can put the following code in your SetUpFixture
class. (You can do this with older versions but you will need to do whatever equivalent that has to the SetUpFixture
, or copy it in to the test itself.)
[SetUpFixture]
public class SetupFixtureClass
{
[SetUp]
public void StartTesting()
{
System.Diagnostics.Debugger.Launch();
}
}
What Debugger.Launch()
does is cause the following dialog to show up when you click Run inside NUnit.
You then choose your running instance of visual studio with your project open (the 2nd one in my screenshot) then the debugger will be attached and any breakpoints or exceptions will show up in Visual Studio.
In Nunit 3.0.1 (I'm using VS2013), Open from main menu > Test > Windows > Test Explorer. Then in "Test explorer", right-click the test case, you might see:
Hope this helps.
Install TestDriven.NET, which is a plugin for Visual Studio
From there you can right click on your unit test assembly and click Run Tests to run the whole suite, right click on a TestFixture class to run just the tests in that class, or right click on a Test method to run just that method.
You also have the option to Test With Debugger, if you need to breakpoint into your tests in debug mode.
Try NUnitit - a open source Visual Studio Addin for Debugging NUnit Test cases
HomePage - http://nunitit.codeplex.com/
Remove ProjectTypeGuids from the project file.
Now with pictures:
- Run NUnit gui (Download 2.6.2 from here) then go to
File -> Open Project
Select your test
.dll
from bin folder (C:\......\[SolutionFolder][ProjectFolder]\bin\Debug\xxxxTests.dll
)Go to Visual Studio
Debug -> Attach to process
(Attach to process window will open)From the list scroll down and select
nunit-agent.exe
then clickAttach
At this point breakpoints in your tests should turn ripe red (from hollow).
Click
Run
onNunit Gui
and you should get your breakpoint hit...
Hope this saves you some time.
If you are able to get the console / or GUI working, but your breakpoints are not being hit, it may be because your app is running a different .NET runtime than NUnit is. Check to see if your nunit-console.exe.config / nunit.exe.config has the runtime specified.(The configurations live in the same directory as the nunit exe's.) Specify the runtime using the startup node:
<configuration>
<startup>
<supportedRuntime version="4.0" />
</startup>
If project path contains spaces e.g. "New Project" in path <path>\bin\Debug\New Project\Quotes.Domain.Tests.dll
then enclose the Start Option --> Command Line Arguments project path in double quotes.
I spent a lot of time to figure this out.
Regarding what Mr. Patrick McDonald said
As my test project is not the startup project in the solution, I run my tests by right-clicking on the test project and choosing Debug --> Start New Instance
I tried to apply for my test class library but got some error regarding the path, so I tried to remove the 'Command Line Arguments', and luckily it worked well and as expected.
It sounds like you are trying to use the wrong library. NUnit can only start if the dll you are using contains TestFixtures.
+1 on TestDriven.Net. I've had the chance to use it a number of times. You can download the personal version for evaluations purposes according the the license at http://testdriven.net/purchase_licenses.aspx.
I got the same error with MSTest. I found that in the Test Output window, some of the tests had duplicate IDs and could not be loaded. I removed all duplicate tests and now I was able to run the tests when i start the project.
There is also an extension now "Visual NUnit" that will allow you to run the tests from within Visual studio much like the build in test framework handles. Check it out its in the extension manager.
Open Visual Studio ---> your Project---> Select 'Properties'---> Select 'Debug' --> Select 'Start external program' and set the path of your NUnit there(Eg: Start external program = C:\Program Files\NUnit 2.6.2\bin\nunit.exe) ---->Save
After setting this just click Debug
For me solution was to adapt nunit configuration file. To use nunit with 4.5-.Net framework and x64 build option, I had to add one line to startup tag (supported runtime-version).
<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- Comment out the next line to force use of .NET 4.0 -->
<supportedRuntime version="v4.0.30319" />
</startup>
Afterwards, I could start by right-click on the Testproject Debug -> Start new instance. Before, I needed to again manually attach the project to the process.
My Debug properties were, C:\Program Files (x86)\NUnit 2.6.4\bin\nunit.exe with argument of the location of the .dll to be tested.
More information: nunit for testing with .NET 4.0
See if this helps.. How to add NUnit in Visual Studio
(RighteousRant)Although personally I don't like this approach.. If you need a debugger while you are test-driving your code, it's a "smell" in that you do not have enough confidence/know how your code works & need the debugger to tell you that. TDD should free you from needing a debugger if done right. Use 'Attach debugger to NUNit' only for rare cases or when you are wading in someone else's code.
참고URL : https://stackoverflow.com/questions/759854/how-do-i-run-nunit-in-debug-mode-from-visual-studio
'IT박스' 카테고리의 다른 글
Python에서 퍼지 문자열 비교 고성능, Levenshtein 또는 difflib 사용 (0) | 2020.07.18 |
---|---|
JSON.NET을 사용하여 문자열이 유효한 JSON인지 확인하는 방법 (0) | 2020.07.18 |
OpenSSL 연결을 거부하는 Homebrew (0) | 2020.07.18 |
LINQ to SQL : 여러 열에서 여러 조인 (0) | 2020.07.18 |
CancellationToken이 CancellationTokenSource와 다른 이유는 무엇입니까? (0) | 2020.07.18 |