I’m writing unit tests for a large solution which consists of a bunch of projects. Some small, calculation, utility type projects are in managed C++ and the rest are C#. When I run my tests under the GUI I get this error on one of the C++ DLLs:
Instrumentation error while processing file Util.dll:
Error VSP1014 : Unable to open file 'F:\src\Util\bin\Debug\Util.dll' for writing..
Now, under Team Suite 2005, this seems to be a well-known problem but that Knowledgebase article does not describe what is wrong here. For one thing, the error message is different even though the error number is the same. For two, this is my DLL so I have the PDB file for it. And for three, if I hop to the command line immediately after this error and invoke mstest.exe manually, the test runs fine. I don’t get the same error and code coverage is generated.
For now I think all code coverage will have to be done on the command line, as I’m completely stymied now. I can’t see any way around this.
Personal
.Net, Coding, VisualStudio
Settings I should make on a new Visual Studio install so it doesn’t annoy me to death:
- Projects And Solutions | General | untick “Always Show Error List If Build Finishes With Errors”
- Projects And Solutions | Build and Run | “On Run, when build error occurs” set to “Do not launch”
- Projects And Solutions | Build and Run | “MSBuild project build output verbosity” to “Medium”
- Source Control | Environment | set “Editing” to “Prompt for Check out” (I prefer to be warned)
- Text Editor | C# | Formatting | New Lines | untick all (K&R style)
- Debugging | untick “Break all processes when one process breaks” (needed for Edit and Continue under Vista x64)
- Test Tools | Test Project | untick all (unless you want tons of autogenerated semi-useless tests)
Personal
Coding, VisualStudio
Gah!
Say I am writing a unit test for a class that converts metres to feet. This, naturally, involves floats. Ideally my code looks like
float expected=32.91; // in feet
Distance dist = new Distance (10,”m”);
Assert.AlmostEquals(dist.convertToUnit(”ft”),expected);
where the “AlmostEquals” method does something smart like compares the first decimal place or so. I think JUnit/NUnit/etc actually allow you to spec a precision.
Microsoft haven’t managed this, so I have to write stuff like
float expected=32.91; // in feet
Distance dist = new Distance (10,”m”);
float difference = Math.abs(expected - dist.convertToUnit(ft)); // java ism, not sure of the .net Abs method offhand
Assert.IsTrue(difference<0.01);
Unit tests need to be as crystal clear in their intent and as quick to write as possible. Every little tiny rough edge will catch your project thousands of times over. So a big “bah” to Microsoft for this one.
Personal
.Net, Agile, Coding, Rants, VisualStudio
Basic stuff
- shift-F6 - recompile
- F8 - go to next Error
- F12 - go to definition (of class, method, variable…)
Tests
Ctrl-R and then:
- A - run All tests in solution
- T - run all Tests in current context
- N - run all tests in Namespace
- C - run all tests in current Class
Add Ctrl as a modifier to the key above and you will debug tests instead of running then.
See also: http://blogs.msdn.com/robcaron/archive/2007/01/29/1552795.aspx.
Personal
Coding, VisualStudio
Recent Comments