# Saturday, June 30, 2012

MsTest, Nunit, MbUnit etc

Unit testing is now available in VS 2012 Express. In the paid-for SKUs, you can use other unit test frameworks, not just MSTest. For instance, NUnit, MbUnit and so on.

First, install an adapter via Extensions.

NunitTestAdapter

Then install the framework via Nuget- and start writing tests!

NunitTests

Test windows

TestExplorerThere's now only one, the Test Explorer. Most people only ever used the Test Results before, and Test Lists was unusable. It has a thin red or green bar (at last!), and simple splitting into Failed and Passed tests (now with timings).

There's a search with filters ("FullName: Domain.Tests.MyTest"). For solutions with large numbers of tests this might be awkward- I'd like to see more customization of the result tree (by project/folder or namespace), and more filters.

The results at the bottom of the window are summarized, but you can still click through to the test and stack.

There's a button to make every build (Ctl-Shift-B) also run the tests - "Run Tests After Build". Builds and test are run in the  background so it doesn't stop you coding (well, my underpowered 32bit laptop is less responsive, but it's vastly better than previous versions of VS). Not so good if you include some integration tests, but nice nonetheless.

RunTestsAfterBuild

Features

Unit tests support async tests. And code coverage (in Premium and Ultimate only) is much easier- no .testsettings, no having to select the dlls, just right click the tests (or add /enablecodecoverage on the vstest.console.exe command line).

CodeCoverage

You can't test private methods anymore (didn't use that anyway). You can't Generate Unit Tests from a method either. In VS2010 I used this a fair amount- I got a test project with the correct references, and the correct namespaces as well, even if the stub test it created normally had to be deleted and rewritten straight away. I'll miss that.

Key Mappings

Of course, they broke something. I always use Ctl+R-T to run the current test. Well, I hold Ctl and type R then T. Which just doesn't work in VS2012. You have to hold Ctl and type R, then release Ctl and press T. The combination I used, which turns out to be Ctl R,Ctl T, isn't mapped in VS2012. You can remap it manually. Very annoying.

CtrlRT

Microsoft.Fakes: Stubs and Shims

These are mocking classes, similar to Moq, NMock and RhinoMocks, and derived from the Pex Moles project. It's simpler than Moq: there's no "Setup(" or "Verify". It's also VS Ultimate only (not in Premium or Professional). Personally I much prefer to do simple manual stubs (implement an interface in the test project) than full mocking. Full mocks are powerful but you end up with loads of code setting up the tests (tight coupling), and they make it easy to add too many dependencies (just because you can test it doesn't mean you can forget all about the SRP).

Microsoft.Fakes isn't going to replace mocking frameworks (there's no behaviour verification). The shimming is very powerful (and dangerous), similar to TypeMock Isolator and other expensive tools.

To add Fakes, right click the references.

AddFakesAssembly

You'll get a reference to Microsoft.QualityTools.Testing.Fakes and a project folder called Fakes with an xml file in it. For example, in a web application, you'll probably want to fake System.Web so you handle all the HttpContext/ Request stuff.

Stubs are simple (MSDN). Let's stub our input object and initialize it's value. All properties are automatically prepared to return the defaults (0s or nulls). The stub method (in the .Net framework or a local assembly) has a "Stub" prefix.

        [Test]
        public void Test20()
        {
            //arrange
            var entity = new ClassLibrary1.Tasks.Fakes.StubEntity();
            entity.Value = 20;
            var processor = new Processor();

            //act
            var result = processor.Execute(entity);

            //assert
            Assert.That(result.Value, Is.EqualTo(20));
        }

Shims are more difficult and powerful (MSDN).

Here's a method we want to test:

    public class FileReader
    {
        public string ReadAllText(string path)
        {
            return System.IO.File.ReadAllText(path);
        }

Here's how we can test it. Here we have to fake the System reference (which includes mscorlib). Note for shims, we have to have a ShimsContext. The prefix is "Shim" and methods and properties are prepared with lambda functions.

        [Test]
        public void ReadAllTextTest()
        {
            //arrange
            string result;
            var reader = new FileReader();
            using (Microsoft.QualityTools.Testing.Fakes.
                ShimsContext.Create())
            {
                System.IO.Fakes.ShimFile.ReadAllTextString = (arg) => "x";

                //act
                result = reader.ReadAllText(@"X:\doesnotexist\notThere.txt");
            }

            //assert
            Assert.That(result, Is.EqualTo("x"));
        }
posted on Saturday, June 30, 2012 3:57:04 PM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, June 29, 2012

Last time at TechEd 2010 in Berlin was a little disappointing. After taking a year off, Microsoft moved this time to Amsterdam.

20120628_43020120627_417

Ok, I know we're not supposed to be sightseeing, but central Amsterdam is fun and easy to explore on foot. Another incidental but important point: Amsterdam in June is a lot warmer than Berlin in November. The weather was warm and humid under grey skies. The conference air conditioning struggled a little at times, so it was a little uncomfortable.

20120627_389

The venue was a little outside Amsterdam centre, but easily accessible by Metro. Finding rooms was, as always, a bit challenging, but by the middle of the week we had sort of worked it out.

I bet 90% of attendees tried to press the big buttons on the check-in screens. Turns out they weren't touch screens, you had to use the mouse. This at an event promoting Windows 8's touch screen abilities. Even more lame was that Wi-Fi was down for all Tuesday.

The bag was certainly nicer than 2010's. No T-shirt or other swag. This is the week that Google's developer event gave every attendee a new phone, a new tablet, and their new media streamer device. No Surface tablets or Nokia phones here. This is the first place I've seen anyone else with a Windows Phone- there were quite a few around. Three quarters of attendees had iPhones or Androids though. This is about as faithful an audience that Microsoft can get, and Windows Phone is in a minority. That's pretty bad for Microsoft and Nokia.

We'll get TechNet subscriptions, but they don't contain Visual Studio. For developers, who generally feel like second-class citizens at these events, it disappointing. Give us a cheap tablet with Windows 8 RC to play with, and we might be a little less sceptical about Metro. If we can't get enthusiastic about it, no-one will be. Why not DVDs with the RCs of Windows 8 and Visual Studio 2012 just to save us some bandwidth?

There were competitions to win Lumia 900s in the expo, but otherwise swag was disappointing there too.

20120626 dinner1 Dinners were vast - the scale is always impressive. Good food, too.

20120627_412The delegate party was at the Amsterdam arena, and that was a pretty good venue. Plenty of beer, cheese, and other nibbles, and huge screens to show the football. The music was way too loud, though (we're old boring gits, not teenagers).

20120627_0915 AmsterdamArena TechEd2012

20120626_387The keynotes on Tuesday and Wednesday heavily promoted Windows Server 2012 (Tues) and Windows 8/ metro (Wed). The key message from the 2nd keynote seems to be that Windows 8 scales uniformly up from Phone to tablet to desktop. Which is a different story to Apple, who have a clear distinction between iOS and the OS X versions (and MS's own previous CE/ full Windows split). A few glitches when the Metro gestures didn't work properly, which was amusing and disturbing.

My impression is that while it might work well on a small touchscreen, it's not obvious or easily discoverable for a desktop. The demo applications look nice, but most internal and third party business applications look like crap and there's nothing to make the average developer into a decent UX designer. Even properly designed metro apps use lots of whitespace, and have a low information density. Being chromeless actually makes it more difficult to understand what you can do (the Windows Phone IE has tabs, but I still haven't figured out how to switch between them- I think Windows 8 metro IE is the same). The limited choice of full screen or side-by-side docking is just inadequate for a lot of normal PC users.

There were some good sessions. Honestly I'm not sure I learned a lot new, but it most sessions were a good review and clarification of what's current (see my Azure posting). All the information is already on the internet, so a few sessions turned out to be quite boring. But it can be hard to keep up when searches bring up old blog posts that are way out of date, and the sheer range of things that are going on. Best session was Scott Gu's Azure introduction (some of the following Azure sessions were repeating the same information, and were quite dull as a result). Mads Kristensen from the asp.net team was great too, showing current Visual Studio work that only existed on his computer.

The last one was disappointing because there wasn't any new stuff coming out. This year there is, so overall it was worthwhile (thanks to my company for paying for it!). I wonder if these conferences will still be relevant much longer. I'm not arguing that we should get lots of free swag, but they do have to give a compelling reason to physically attend. apart from all the free beer, of course.

posted on Friday, June 29, 2012 10:16:38 PM (Romance Daylight Time, UTC+02:00)  #    Comments [0]
# Thursday, June 28, 2012

azurelogoWebsites are new in Azure From conversations and talks at Teched:

Web Roles Websites
The standard offering New (summer 2012). In preview and discounted at time of writing.
For asp.net/php/html same
Use Azure SQL/Blobs/Table storage. Can use the new Caching. same
- Has a persistent shared disk.
Production and staging. Instant switch for releases. No. You upload to the live site, so a long release will mean the site is broken for that time ( but see below- you can do diff releases)
Can install dependencies (3rd party installations etc, GAC) Bin-deployment of dlls only - or one of a small number of packages like Umbracco.
Release as cspack. Spins up new VMs for each release. Release by web deploy, git, TFS, FTP.
RDP access No. Just FTP.
   

In conclusion:

Web sites simplify the story for simple web sites. But having no staging is a bit limited.

Web roles are better for more complex sites, with dependencies and/or worker roles.

There is no option to upgrade a website to a web role.

All the above will probably be obsolete is 6 months as the features expand.

posted on Thursday, June 28, 2012 11:24:41 PM (Romance Daylight Time, UTC+02:00)  #    Comments [0]