# Sunday, February 14, 2010

Visual Studio 2008 sp1 introduced background compilation so it can underline errors while editing (like Word underlines misspellings). It's been in Resharper for ages. You can have both Resharper and VS error underling- they don't conflict.

In Visual Studio 2010 it's off by default (and Resharper 5 isn't released yet), so you need to turn it on. It's Tools-Options-Text Editor-C#-Advanced. Check underline errors in editor and show live semantic errors.

intellisense

posted on Sunday, February 14, 2010 8:50:16 AM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Saturday, February 13, 2010
The release candidate of Visual Studio 2010/ .Net 4 is out at http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx
You have to uninstall VS2010 and TFS 2010 before installing, which has two reboots.

The main changes are apparently performance improvements. I spent 20 minutes playing with my (small) projects and didn't notice much difference. The splash screen (now a darker blue I think) sits there for ages before VS2010 appears, but that's no worse than any Visual Studio version before. The real test will be building large multi-project solutions which I haven't tried yet.


posted on Saturday, February 13, 2010 8:01:54 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Saturday, January 30, 2010

I spent some time working in quite agile, test-focussed environment, but lately I've been in organisations that like the idea of testing, but don't really practice it.

Trying to use testing helps both in proving something works, and because it makes you structure your code so it can be tested (more modular code, reduce coupling) which makes it easier to understand and maintain.

"Pure" test-driven development is a big step, and the existing code base may make it very difficult. So start small, pick the battle fronts where you can win, refactor, organise your tests. Use integration tests but focussed and well structured.

Tests vs time

The standard argument is "Writing tests takes lots of time so only do it if you have time at the end".
Initially it takes time, but unless your code is bugless first time, the iterations of manual testing/ fixing may take more time. So it's (time to code automated test) vs (time to manual test). The latter can add up over the lifetime of the software, and the major win of automated tests is finding regressions. Assess the cost-benefit, it's doesn't have to be 100% coverage full TDD vs nothing.

"You have to F5 and manually use your application anyway".
True, but automated tests can cover all the permutations you don't do in manual tests.

TDD vs Visual Studio

Autocomplete make test-before-code difficult. The consume first mode in Visual Studio 2010 looks like it will help. Up until now, the closest to real TDD that I've done involved stubbing the classes and methods before writing the tests.

TDD is more than testing of course. It's supposed to force you to design simple loosely coupled components. It certainly makes you focus on your API.

Tests vs refactoring

Refactoring tools (Resharper, CodeRush) mitigate some of this, but most major refactoring will have a big impact on a large bank of tests. So yes, many of your tests may be thrown away and you start again. The solution to to keep the tests well structured and named (yes, easier said than done).

Unit tests structure and readability

Things I've found helpful:

  • the test project and it's subject should look identical: one test class per class. If the test class is too big, it's a good indication that the class is doing too much, but you can split up the test class with partial classes.
  • TDD guides suggest you don't test private methods, and so far this has worked well for me. I don't use the MSTest private accessors, although very rarely I will write a little reflection code to set a private field rather than use the public property. Internal methods and InternalsVisibleTo are very useful.
  • Internally in the test method, the "arrange / act / assert" comments split things up.
  • Underline-delimited words in test method names are more readable than Pascal case.
  • Test methods have to be readable, not elegant code : avoid simple refactorings (extract method) that hide what's going on, use lots of cut'n'paste code.


Unit tests vs Integration tests

Developers often have the idea that they should only do unit tests, and integration tests are a really bad thing. Of course you can and should refactor to use interfaces with DI / mocks so code can be unit tested without dependencies.

But data access and UI (at least non MVC flavours) are by definition mostly integrations and not easily testable. If you can test them with integration tests, you often have the most interesting and useful tests (unless you love manual testing). All those individual classes are pretty dumb and unit testing doesn't reveal as much.

Integration tests tend to be much longer and more complicated- there's almost always setup/ class or testInitialize and teardown / cleanup. But structure it well and after the writing the initial setup and first test, other tests just follow the same pattern and become very easy.

Integration tests tips

  • Break it down into small tests. The temptation is to do an end-to-end test (login-navigate-create record-find record-edit record-delete record-logoff). To start, one test = one operation/ form/ page (at most). For UI, you probably have to start with launch app/ login, but stop there- other tests can then call the login and carry on. If you change the login, one test changes and the others will be unchanged. 
  • Database tests: A local SqlExpress database file is a neat testing target in the test project, if you can keep it up to date.
  • Database tests: You can wrap tests in transactions that are not committed (and thus rolled back)
  • Database tests: Linq2Sql is helpful to verify your data access is doing the right thing.
  • Web UI tests: for asp.Net you should use Watin (a framework to run IE - and now Firefox- from tests). You really can write the test, then code the webpage, in true TDD fashion (I did!). Visual Studio 2010 coded UI tests work similarly, with a nice recorder- not just IE, but Firefox, winforms, and WPF (Chrome/Safari/IE6 aren't supported, and amazingly Silverlight isn't either). Telerik has a similar web-test UI studio (IE, FF, Safari and Silverlight), but it isn't cheap.
  • File IO: In MSTest this is fairly easy in the deployment directories, which are temporary directories created each test run (under solution-level folder Test Results). By default, deployment is enabled (see in LocalTestRun.testrunconfig). Environment.CurrentDirectory (and TestContext.TestDeploymentDir) have the full path. Test assembly contents with Copy to Output Directory = Always copy do not get copied (only the dlls) so add the attribute [DeploymentItem("Data.xml")]
posted on Saturday, January 30, 2010 8:25:12 AM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Sunday, December 13, 2009

Team Foundation Server 2005/2008 didn't make much sense for small teams. TFS 2010 Basic allows you to have a simple, quick source control and issue ("work item") tracking for individuals. It should at least see the end of SourceSafe. Whether it will draw back those who have already jumped to subversion remains to be seen.

Creating workspaces and team projects is not something I'll do very often, so I'll record the steps here.

Download VS2010 and TFS 2010 from Microsoft and install. The TFS configuration wizard kicks in after the install, and is pretty simple.

Connect to TFS.

connect to tfs Spot two ways to do it in this screenshot.

Select TFS server - click "Servers" button

select tfs server

The servers list will be empty at first so click "Add" button

select tfs server 2

Fill in the server name.

select tfs server 3

Now the project collection is shown (always DefaultCollection with basic). Click "Connect"

select tfs server 4

Workspaces

You need to set up a workspace - the local path on your computer (in VSS this would be your "working directory").

In VS2010, File-Source Control - Workspaces.

file-source control-workspaces

It's empty to start. Typically you only have one per TFS server. Click "Add"

tfs workspaces

Map the server folder ("$/") to your local folder (here, C:\Dev)

tfs workspaces 2 

New Team Project

Each TFS contains a number of collections (these root collections are new in 2010), Each collection contains a number of team projects. The team project is typically an application, comprising one or more solutions plus work items and documents. More information here (Codeplex guidance)

You can start a team project from the VS2010 File-New-Team Project or the team explorer.

new team project

It's a simple wizard. Name it, pick the type (you may have a Scrum template), Next, Next, Next.

new team project 2 new team project 3 new team project 4 new team project 5

new team project 6

Your source control is now empty. Don't just put a solution in there. Add New Folder, and use this to put your first code in. I'm calling it Trunk, but TFS people seem to call it "Main".

new source control folder

I created a Visual Studio solution within my workspace\project\trunk folder. I add it to source control.

add solution to source control

And check in (pending changes window)

pending changes

Why a subfolder called "Trunk" (or "main")? So I can create a branch.

I also create a "Branches" folder under the team project, and branch to a subfolder of that. Here I'm creating a branch for a new version (v4).

branching

There's detailed guidance on TFS branching on Codeplex.

posted on Sunday, December 13, 2009 6:07:51 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Saturday, December 12, 2009

scottguusualsuspects

Here I am at the ScottGu impersonators gathering. I'm in the red polo.

scottgucrowd

Ok, actually this was a Scott Guthrie presentation - vs2010, asp4, silverlight 4, asp mvc2. Plus some related stuff like the IIS SEO module and IIS media streaming. And even a demonstration of rickrolling.

Between the lines- the web stack is still evolving strongly (especially SL and MVC, but asp webforms is getting attention too), windows forms is dead, silverlight and silverlight out of browser will replace most of desktop WPF (which is just for Visual Studio scale apps)

scottgulineup I'm in the back row, under the "d" of msdn and looking to the side wondering if ScottGu was in that direction.

posted on Saturday, December 12, 2009 8:31:53 AM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Friday, December 04, 2009
Lots of nice new stuff in VS2010 intellisense. See the ScottGu blog post which mentions:
  • "contains" matching (not just "starts with"),
  • Resharper-style "camel-humps" (PIC for PageIndexChanged).
Also particularly nice for TDD-style coding is the "consume first" mode.
You toggle in with control-alt-space, and it stops the auto-complete. It prevents auto-selecting the wrong thing when you name a new class or method that's close to something that's already in scope.
Very handy in TDD tests, because the classes and methods don't exist until you've written the test.

normal intellisense with autocomplete- press space, and you get CategoryTest. Opps!



Consume first (Ctrl-Alt-Space): no auto-select (you have to click from the dropdown), and the suggestions includes "Category" even through it doesn't (yet) exist.


It then provides "Generate class" hints, and a "Generate Other" dialogue for more control.


More info at the bottom of Soma's post

posted on Friday, December 04, 2009 9:06:01 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Monday, November 30, 2009
The best page with all the ISOs (VS in all editions and TFS Basic) is MSDN
http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

So far, it looks good. Lots of nice touches like editing the start page MRU project list (at long last).

Unfortunately a lot of the really nice new stuff is Ultimate version only (all the new UML diagrams and architecture validation and intell-trace historical debugging). The coded UI tests/ UI test recorder seem to be premium edition only.

I suspect most of these (and the other high-end features) will need to drop to professional SKU to be widely accepted (as MSTest was when VS2008 came out) - oh well, looking forward to 2020 :)


posted on Monday, November 30, 2009 1:46:07 PM (Romance Standard Time, UTC+01:00)  #    Comments [0]
# Saturday, November 28, 2009
This blog is probably going to contain odd .Net notes and links, as reminders for myself.

I'll be shocked if anyone actually subscribes!

posted on Saturday, November 28, 2009 8:43:17 AM (Romance Standard Time, UTC+01:00)  #    Comments [0]