How to debug in Visual Studio with NSpec - tdd

how do I debug in visual studio with NSpec? I've resharper installed I need to step into my test code.

Another good option is to just type
System.Diagnostics.Debugger.Launch()
in the test you want to debug. You'll get a Visual Studio prompt to debug the test.
I would also recommend taking a look at specwatchr.

At least in Visual Studio 2013, the NSpec Test Adapter (by {o} Software) seems to do the trick. Find it in the Extensions gallery. Then just right-click on the test in the Test Explorer and hit Debug.

I use a simple trick that let's me debug NSpec with resharper out of the box. The idea is to have your own version of "nspec" class instead of DebuggerShim.cs (somewhere in your test project):
[TestFixture]
public abstract class nspec: global::NSpec.nspec
{
[Test]
public void debug()
{
var currentSpec = this.GetType();
var finder = new SpecFinder(new[] {currentSpec});
var builder = new ContextBuilder(finder, new Tags().Parse(currentSpec.Name), new DefaultConventions());
var runner = new ContextRunner(builder, new ConsoleFormatter(), false);
var results = runner.Run(builder.Contexts().Build());
//assert that there aren't any failures
results.Failures().Count().should_be(0);
}
}
After that you will get Resharper's test icon next to your spec:
For more details see this article: Debugging NSpec with VisualStudio/Resharper – simple trick

Resharper supports NUnit and MSTest runners only (AFAIR). Open the Resharper "Unit Test Explorer" window and see if it lists your NSpec tests there..
If not, you need to fallback to specifying an external program for debugging (The NSpec runner exe) - See this question on how to configure this in Visual Studio.

Related

Resharper 8 and Test Explorer not finding xUnit tests in VS2013

I have the following test code. But cant see the tests in either Test Explorer or Resharper.
What am I missing? I have made the class public, I have tried cleaning the project, i have tried both default architectures in the test settings. I am running Windows 7. xUnit 1.9.2, Resharper 8.1 Full Edition
using Xunit;
namespace MonkeyFace.Specs.Registration
{
public class ValidApplicationReceived
{
[Trait("A valid application is submitted","")]
[Fact(DisplayName= "A user is added to the system")]
public void User_is_Add_To_System()
{
Debug.Print("hi");
Assert.Equal(1,1);
}
Do you have the xunit ReSharper runner extension installed? You need to install it from ReSharper -> Extension Manager.
If it's installed, do you see anything in the editor? Any icons next to the class or method to indicate tests?
I had to install the xUnit.net runner for Visual Studio 2012 and 2013 by using the Tools -> Extensions and Updates menu in Visual Studio

Visual Studio Cannot Scan/Find MSTest Methods

I converted a project with nunit tests, so that it had mstests instead. It compiles, and when I right click on the project, I can select "run unit tests." It works, and the tests execute successfully.
However, I cannot see my tests in either the "Test List Editor" or the "Test View." I've tried:
selecting the "refresh" button in both those lists
rebuilding the solution
re-starting visual studio
Activated background discovery (I do have VS 2010 SP1, and resharper)
None of these, alone or in combination, has worked. What else can be tried, to force Visual Studio fully to recognize these tests?
The answer, I found, is that I must convert a class library to an MsTest project.
Also make sure that your test class is public, I spent almost one day trying to figure out why the MS test frame can't discover my test until I modified the access modifier from the default to public

Can the Visual Studio (debug) Output window be programmatically cleared?

is it possible to have a way to clear the Visual Studio OUTPUT window, programmatically? For example, the SysInternal's debugger app called DebugView has the specific command called DBGVIEWCLEAR .. which clears the log window.
Please don't say: right-click, clear window .. with the mouse. I know that, but that's not what i'm after.
For VS 2008 try this code
EnvDTE80.DTE2 ide = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.9.0");
ide.ExecuteCommand("Edit.ClearOutputWindow", "");
System.Runtime.InteropServices.Marshal.ReleaseComObject(ide);
"VisualStudio.DTE.9.0" will change from VS version to version.
For VS 2010 :
//Add reference EnvDTE100
static void ClearOutput()
{
EnvDTE80.DTE2 ide = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.10.0");
ide.ToolWindows.OutputWindow.ActivePane.Clear();
}
The first answer works on any release after Visual Studio 2005, but it seems a little flaky. I had to put a 1 second delay before clearing the console and couldn't get it any better than that. No idea why, but it's better than nothing. It also only works if you're only running one instance of Visual Studio. Maybe I"ll make an extension that looks at the RunningObjectTable to pick the right version.
At any rate, this works more or less.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace VisualStudioHelper {
public class VstHelper {
// Add a Project Reference to "Microsoft Development Environment Properties 8.0"
// (the one for Visual Studio, not SQL Server)
public static void VstClearOutputWindow() {
if (!Debugger.IsAttached)
return;
Application.DoEvents();
Thread.Sleep(1000);
EnvDTE80.DTE2 ide = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.10.0");
ide.ExecuteCommand("Edit.ClearOutputWindow", "");
Marshal.ReleaseComObject(ide);
}
}
}
For VS 2019 try this code
//Add reference to Interop.EnvDTE100
EnvDTE80.DTE2 ide = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
ide.ExecuteCommand("Edit.ClearOutputWindow", ""); System.Runtime.InteropServices.Marshal.ReleaseComObject(ide);
What about Console.Clear()?

Show Visualizers Error "could not load this custom viewer"

When I try to inspect DataSet by standard DataSet visualizer I see this error "could not load this custom viewer".
I wrote simple dataset visualizer, but error throws anyway too.
On other computers with the same configuration visualizer show without any errors.
OS: Windows 7 x86 (Release)
VS: Visual Studio 2010 RC
has somebody any ideas?
I reinstall VS with no effect.
Try the following.
-Go to Tools->options->Debugging->Plz Uncheck "Use Managed Compatibility Mode"
I had the same issue in VS 2015 and none of the answers here helped me but I found an issue on github that described my problem.
The solution, or workaround might be more accurate, for me was to turn off the option "Use the legacy C# and VB evaluators" that I (apparently) had turned on in Tools -> Options -> Debugging -> General.
The best way to diagnose this is to debug Visual Studio itself. Try the following
Get Visual Studio into the state where you want to use your Visualizer
Attach another version of Visual Studio to the original one (managed only)
Disable Just My Code (Tools -> Options -> Debugger -> uncheck "Just my Code")
Go to Debug -> Exceptions
Check the Throw box for "CLR Exceptions"
Switch back to the first VS and Attempt to show your Visualizer
This should throw an exception which will then show up in the second instance of Visual Studio. Please post back with this information if it's not enough to solve your problem.
For me. Visual Studio 2010 restart helped.
I had the same issue in VS2017, I tried a lot but nothing was worked and finally, I reset all the VS settings which I made and the error was gone.
https://blogs.msdn.microsoft.com/zainnab/2010/07/16/reset-all-your-development-settings/
I found workaround!
I changed source code of DevExpress module and recompile it. After that I undo parameter to NetFx40_LegacySecurityPolicy enabled="false", and enjoy. :)
File is "%DeveloperExpress.NET%\Sources\DevExpress.Data\Utils\Security.cs"
using System;
using System.Security;
using System.Security.Permissions;
namespace DevExpress.Data.Helpers {
public static class SecurityHelper {
public static bool IsPartialTrust {
get {
return !IsPermissionGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
}
}
public static bool IsPermissionGranted(IPermission permission) {
bool result = true;
/* (changed by Lion)
try {
PermissionSet ps = SecurityManager.ResolvePolicy((System.Security.Policy.Evidence)null);
ps = ps.Copy();
ps.AddPermission(permission);
ps.Demand();
}
catch (SecurityException) {
result = false;
}
*/
return result;
}
}
}
For me, I had written my own visualizer for a type that I had created. Apparently, this was interfering with VS 2017's ability to display the built-in visualizer for datasets. Once I removed my own visualizer and the Microsoft Debugger Visualizer reference, I could use the built-in ones.
I have written other visualizers in earlier versions of VS that didn't cause any problems.
I found the cause of this error.
According this advice http://go.microsoft.com/fwlink/?LinkID=155570 I add to devenv.exe.config this parameter
NetFx40_LegacySecurityPolicy enabled="true"
and with this parameter in .config file I have the error when try to open DataSet visualizer.
When I remove this parameter all became ok. Execption "The security state of an AppDomain was modified by an AppDomainManager configured with the NoSecurityChanges flag" fixed too.
But I NEED NetFx40_LegacySecurityPolicy enabled="true" parameter to work with old projects.
Clearing Visual Studio Cache fixed it for me.
Just follow these basic steps:
Step 1: clear the Component Cache
Close Visual Studio (ensure devenv.exe is not present in the Task Manager)
Delete the directory:
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
If step 1 doesn't work then
Step 2: cleanup your user’s temp folder. Delete this directory:
%USERPROFILE%\AppData\Local\Temp
If step 2 doesn't work then
Step 3: Delete all these directories:
%USERPROFILE%\AppData\Local\Microsoft\Team Foundation
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio
%USERPROFILE%\AppData\Local\Microsoft\VSCommon
Credit : https://errorhandlinginskills.wordpress.com/2018/07/28/how-to-clear-visual-studio-cache/
visual studio -> Tools-> options-> Debugging-> "Use Managed Compatibility Mode" - uncheck this and maybe it works fine then.
in visual studio 2019 community after an update between 16.4.x - 16.7.5 mine was broken all I had to do was uncheck "Warn when using custom debugger visualizers against potentially unsafe processes (Managed only)" and it allowed me to see a visual of the datatable. Under the tools>options>Debugging>general menu.
Just Restart your system. Your problem will be resolved.

How to debug mbunit/Gallio unit tests in visual studio

I am trying to figure out how I can hit breakpoints in my unit tests that are written with MbUnit/Gallio. I tried running Gallio.Icarus, attaching vs debugger to it, the breakpoints weren't hit.
Next I tried to start Gallio.Echo from project properties, but I was getting an error message, after supplying the dll, saying only .exe's can be tested.
The unit test runs fine from Gallio.Icarus, however, I am unable to debug them.
Thanks!
Grab Gallio v3.0.6 Update 1. Load up your tests and click on the shiny new "Debug" button in the Icarus GUI itself.
I would use TestDriven.Net for this. It supports MbUnit tests, and you can debug by simply right clicking from within Visual Studio
A much better answer is found here:
gallio test runner plugin to visual studio 2010
The answer is to add the following section to your *.csproj file the after the <ProjectGuid> section section:
<ProjectTypeGuids>
{3AC096D0-A1C2-E12C-1390-A8335801FDAB}
; {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
See Also:
How Does Visual Studio Identiy test projects?
A list of supported VS2010 project types
Second list of GuIDs for supported project types

Resources