NUnit debugging with VWD 2008 Express - debugging

How can I do this?
Is it even possible?
I only see online tutorials for setting up debugging with NUnit for non express versions or for visual studio.
I have setup NUnit, I just can't seem to debug with it.

One trick is to change the class library project containing the tests to a console application and then just create a main method for it.
Easy and effective.

Related

Can't debug NUnit tests with Visual Studio

Trying to debug an NUnit test in VS2010 and is not stopping on the breakpoint. It was working the last time I tried need to debug the test (maybe 1 yr ago) but now it doesn't work.
I've tried the following:
How to debug with vs.net 2008 and nunit?
http://erraticdev.blogspot.com/2012/01/running-or-debugging-nunit-tests-from.html
I've tried attaching, rechecking my installation, updated the config file so it's using the 4.0 runtime, still doesn't hit the breakpoint.
What am I missing?
You can debug nunit tests in VS studio community version only. For this you need to install Nunit3testAdpter. You can add this in Tools -> Extension and updates. or from Nuget packages.
This is a long overdue question but I haven't seen the solution to debug NUnit tests directly within Visual Studio. This is quite easily possible and without any third party tools. All you have to do is configure your test project (which is just a plain old Class library project) so it will start NUnit test runner whenever you hit F5 or Ctrl-F5 (just run, no debugging).
Particularly you will have to configure your project properties to start an external program:
Step by step configuration is very well described in this blog post. It advises you to use NuGet to obtain NUnit test runner and configure project to execute the runner when you try running your library project. As simple as that. Using no specific tools which are usually not free.
There are multiple reasons why this may happen. If your application's target framework is different from NUnit's, then you won't be able to debug, because the tests are actually being run by nunit-agent.exe.
For me, my application was using 4.5, but NUnit's was using 3.5. (You can find this from one of the NUnit GUI applications -> Help -> About)
To fix this, change the nunit.exe.config file to include the following, inside the configuration section:
<startup>
<requiredRuntime version="4.0.30319" />
</startup>
This can also happen when your PDB generation is set to embedded. Switching it to full will allow the nunit test adapter to start with the debugger attached. At that point it can be switched back to embedded and it will debug again.
The setting is on the project properties pages, in the Build tab, then click the Advanced button. I always choose "All Configurations" at the top, so I make sure I'm emitting a useful PDB (or embedding the info) when building Release configuration assemblies too.
The other day I failed to hit a breakpoint in my NUnit debugging. It took me a while to realize that someone had copy/pasted the test into a different file and I was running a different test than the one that the breakpoint was in.
I recently had a similar problem. Changing the project's platform to AnyCPU solved it for me. Also worth checking:
1) Check NUnit's latest version (I was using 2.5.7, updated to 2.6.2)
2) The Target Framework for your test project. I was using .NET 4.0 (you can find it under Properties -> Application, on VS2010)
At least up to vs2010 the debugger can only debug 32 bit apps but not 64 bit apps.
With vs2010 I am using a 32bit nunit.exe version and use "attach to debugger". This workes well for me.
Please upgrade NUnit Test Extension and close the Visual studio so Visx (probably spell) will run and update NUnit tool.
After this you can open your project and run NUnit test project.
It will run.
I tested accurately.
Try changing the test to x64. From the menu do
Test -> Test Settings -> Default Processor Architecture -> x64.
i think u cant debug with Visual studio. better u install TestDriven.NET.
then
Put the BreakPoint on the test method
Right click on the test
method.
select TestWith->Debugger

Developing in Visual Studio 2010 and Sharepoint 2007. Using new SPSite throws errors

I'm re-writing a console application using Visual Studio 2010. The original application was written using Visual Studio 2008 and works OK, but has no tests associated with it. Hence, the idea of re-writing it with tests.
Both applications are working with a Sharepoint 2007 site.
The project compiles but when I try and run it the code below is throwing errors.
SPSite spsite = null;
SPSecurity.RunWithElevatedPrivileges(delegate() {
spsite = new SPSite("http://sharepointdev");
});
return spsite;
I'm running this on Windows Server 2008. I've set the platform target of the build to be x86 (this is in the properties of my project) and in Security I've checked that this is a full trust application. I'm also running the project as an administrator. I've also set the .NET Framework to be 3.5
Is it just a case that SharePoint 2007 just doesn't want to play with Visual Studio 2010, or is there something else I've not yet considered?
I've tried searching on the web and stackoverflow but all the articles I've seen deal with trying to get Visual Studio 2010 to work with Sharepoint 2010.
The exact error I get is 'Object reference not set to an instant of an object' with the debugger high-lighting the SPSecurity call.
If I just use this code
using(SPSite spsite = new SPSite("http://sharepointdev")){
Then I get a FileNotFoundException, which isn't exactly true! I've got plenty of applications that do find a site using that URL. What I suspect the error message is trying to say is that my 2010 application is not being allowed to access the site, but I've not found any clues as to why that should be.
Any clues, hints or suggestions gratefully accepted.
EDIT
I've lifted the code from my VS 2010 project and dropped it into a new VS 2008 project and it ran straight-away.
FURTHER EDIT
I created a simple little console application in VS 2010. By default it uses .NET Framework 4, I had to set this to .NET Framework 3.5. I also set the platform target to be 'Any CPU' and it works. This makes me wonder if there is an issue with the Test Project associated with my first application?
I re-created the console application but this time without a Test Project associated with it (the test project was a class library and worked with NUnit). It ran with no problems. I guess the problem lies within the test project and something there that the solution doesn't like. Probably there's a build there it doesn't like
TL;DR; answer: Switch to Any CPU build - don't choose x86.
I've run into this problem before with a console utility. I got the same FileNotFound error but it's referring to the DLL, not your SharePoint site. Digging a bit I discovered a deeper error of BadImageFormat and realized it was complaining about a DLL or EXE. I guessed it was due to the linking from x86 to MSIL. There's a lot of things that have to happen to marshal calls between the two and I guess it led to an incompatibility. When I switched it (and verified all my support library projects) built to MSIL/Any CPU the application worked with no problems and no other changes.
I use Visual Studio 2010 to develop for SharePoint 2007 all day for a long time now and the only problems I've encountered aren't related to that combination. More often than not it's a quirk of a 3rd party add-on I'm using. For almost all of my development I start with the WSP Builder templates but they are buggy and have a few quirks you have to work around (some severe enough to take down your SharePoint server) so I don't blame VS 2010 directly.

Is it possible to integrate NUnit with VB.net Express Edition? Which is the best way?

I'm a Java Developer wich is learning VB.net for a small project. While coding in Java, we don't have to think a lot about how to integrate our IDE with our unit test framework because most of the IDEs already area integrated.
But now that I'm working on a project which the main requirement is to use VB.net Express Edition, is it possible to integrate this IDE with NUnit? How can I do that? Is there a better practice for this task? What should I do?
No, we can't opt to use Visual Studio, only the Express Edition of VB.net
You can add a test project, reference the nunit.framework DLL. If you can set the startup program in express (via project properties), you can set the startup program for the test project to the NUnit framework GUI. I wasn't sure if express supported that...
Additionally, you can run NUnit stand-alone; open NUnit, point to the test project DLL, and NUnit refreshes as you recompile.
HTH.

Using MSTest in an open source project

A colleague and I are writing an application that we intend to go Open Source with and are trying to decide on a testing framework. Without integration of NUnit (one of us has resharper while the other does not) we are leaning toward MSTest. However, if the majority of people that work on opensource .net applications only have the express edition of Visual Studio, we may have to change our mind on that.
What version of VS do you use and would MSTest turn you off to an Open Source Project?
Personally, I'm using VS:TS, so no, test units in MSTest wouldn't turn anything off for me ;), on the other hand, most probably, you will receive different answers from the majority of people, that are not professional programmers as well (working for money doesn't mean you can not work with / on OS projects) (the question is, how many you will find here).
However, if I understand you correctly, you don't want to use nUnit, because you it's not integrated with VS08, you might then check out these projects:
1. http://sourceforge.net/projects/visualnunit/
2. http://sourceforge.net/projects/nunitaddin/
Integrating NUnit with VS08 doesn't seem to the biggest problem, on the other hand, getting VS with built in testing framework might be a bit harder, at least for some people.
If I truly felt strongly enough to participate in the Open Source project, MSTest alone wouldn't be enough to turn me away. I'd be willing to adapt to whatever the development tools/environment was.
...and for what it's worth, I use the full version of Visual Studio with Resharper.
Frankly I never heared of anyone using the Express editions. everybody I know or I talked with either use the fully fledged Visual Studio environment, or they use the compiler/libraries from the free SDK and some editor on top of it (CodeWarrior, CodeInsight etc) and rely on some variant of make to build.
As for the test framework, is a double edged sword. I'd recommend NUnit, but then... remember what happened with NDoc?
I use MonoDevelop and NUnit.
I use VS 2k8 pro & MSTest as much as possible.
Even Microsoft's open source code (Prism/Composite Wpf) doesn't use MSTest. They use NUnit for that project, I believe.
You may be able to use visual nunit to add an nunit test runner in VS. link I've never used it but it may be worth a shot.
If your problem is integration with Visual Studio, try Gallio. It includes MbUnit, but its runner can run tests from other frameworks, like NUnit, xUnit, etc.
It would turn me off. See MSBuild, NAnt, NUnit, MSTest, and frustration (not written by me!) - I suspect a number of people feel that way. MSBuild seems like a poorly-done copy of NAnt (we use both), and MSTest likewise looks like Microsoft's usual "not invented here" answer to open source. While I realize that there are good business reasons for Microsoft to develop their own tools, those reasons don't apply to their customers.
There are plug-ins to use NUnit inside Visual Studio without ReSharper, or you can always configure it to run from the Tools menu.
If you don't like NUnit, please consider one of the other open source testing alternatives. See NUnit vs. MbUnit vs. MSTest vs. xUnit.net
I think that people who don't use windows will be knocked out of the project by the choice to use MSTest. Most other c# testing libraries are available in mono, which is what mac and linux users would be using.
I don't know how many cross-platform developers you are trying to attract, but if it's an issue then you need to consider Linux/Mac devs.

Using Saxon .NET XSLT processor does not work with intellisense in Visual Studio

I am using the open source Saxon XSLT processor for .NET to execute some 2.0 transforms.
I reference the saxon9api.dll as I would any other dll, and can compile code against this. However Visual Studio does not show any intellisense making the IDE as useful as notepad.
The saxon9api.dll is using the IKVM Java for .NET platform, and I wonder if this is the causing VS a problem. Reflector can inspect the DLL without issue, but I suspect VS is not happy for some reason.
Any ideas?
EDIT:
Surprised that no one else has encountered this behaviour seeing as Microsoft recommends (link is now dead) the use of Saxon in the absense of built in functionality in the framework.
I think I will reword the question to be about assemblies running under IKVM not showing intellisense although I will need to find another IKVM based project to prove that this is the case first...
To make compiling, running and intellisense work in Visual Studio, you need to do the following:
Reference saxon9api.dll, as you already did
Reference IKVM.OpenJDK.Core.dll
Reference IKVM.Runtime.dll (not sure this is needed, but I always include it)
If you are also referencing vjslib, you may run into issues, because it uses a lot of the same namespaces and classnames, leading to ambiguities that can cause Visual Studio's intellisense to get into problems. Perhaps other libraries exist that show the same namespace clashes. In that case, try this on a fresh project first and add the references one by one, starting with Saxon's dependencies first.
After you do this, at least in Visual Studio 2010, 2012 and 2013, you will find that the context-sensitive help is working (image is of VS 2012 with R#):
Note: since this post is old, it may have only applied to Visual Studio 2008 at the time, I have not tested that as I am not using it anyore.

Resources