Thursday, April 15, 2010

Taking Telerik’s Just Mock for a test drive

Telerik has released a beta of JustMock (a mocking framework) they claim can easily mock anything including sealed classes, non-virtual methods, and static classes.  If they can do this great!, but lets see just how well this actually works by taking a look at some of the biggest pains to test: HttpContext and SqlConnection.

 

HttpContext Test

Test: Can I mock HttpContext, set a value, and get the value, in this case Error
   1: ErrorLoger target;
   2: private const string TestError = "Test Error";
   3: public MockILogger MockLogger;
   4:  
   5: [SetUp]
   6: public void Setup()
   7: {
   8:     target = new ErrorLoger();
   9:     HttpContext mockContext = Mock.Create<HttpContext>();
  10:     Mock.Arrange(() => mockContext.Error).Returns(new Exception(TestError));
  11:     target.Context = mockContext;
  12:     MockLogger = new MockILogger();
  13:     target.LoggerInterface = MockLogger;
  14: }
  15:        
  16: [Test]    
  17: public void LogError_SetsLoggerMessageEqualToContextErrorMessage_Test()
  18: {
  19:    target.LogError();
  20:  
  21:    Assert.AreEqual(TestError,MockLogger.Message);
  22: }


Result: Just Mock crashes when it tries to mock HttpContext.

SqlConnection Test

Test: Can I mock a SqlConnection and open a connection with out really opening a connection.
   1: private DataRequest target;
   2: private bool SqlConnectionOpened;
   3:  
   4: public void SqlConnectionOpenedCalled()
   5: {
   6:     SqlConnectionOpened = true;
   7: }
   8:  
   9: [SetUp]
  10: public void Setup()
  11: {
  12:     SqlConnectionOpened = false;
  13:     target = new DataRequest();
  14:     
  15:     var mockSqlConnection = Mock.Create<SqlConnection>();
  16:     Mock.Arrange(() => mockSqlConnection.Open()).DoInstead(SqlConnectionOpenedCalled);
  17:     target.Connection = mockSqlConnection;
  18: }
  19:  
  20: [Test]
  21: public void GetUserList_Test()
  22: {           
  23:     List<string> actual = target.GetUserList();
  24:     Assert.AreEqual(true, SqlConnectionOpened);
  25: }

Result: Just Mock was able to create the mock without crashing but when I try to set alternate functionality to the Open method, recording that I called Open, it crashes saying invalid connection string.  My question is why does it care about a connection string when I’m setting behavior, unless I’m missing how to set this up.

Conclusion

As you can see in the examples the syntax is nice and simple, unfortunately Just Mock failed to pass either of my test and to be honest I’m not surprised, it’s in early beta and I tested it against the hardest problems I can think of to solve, something that none of the other mocking frameworks I have looked at even attempt. 

What really impressed me was that while working on this I tweeted about having problems and within a couple of hours @hkosev (Hristo Kosev) from Telerik, who isn’t one of my followers, tweeted me asking what I was doing to get the errors and asked me if I would mind sending him the source for what I was doing so they could solve the problem, without even asking for help, very nice.

As always here is the link to my source code.

Sunday, April 4, 2010

Using what works

What’s with the hating, can’t we all just get along? The agile guys vs. non-agile, Windows vs. Mac vs. Linux/Unix, and we can’t forget the language wars.  So why do we get so entrenched in the belief that the way we do it is right and everyone else is wrong; call it ego, pride, or something else, it doesn't really matter, why do we do it.  By nature we are problem solvers so why do we have such a hard time accepting other’s ways/tools for solving problems?

 

Agile vs. Non-agile

Having worked in both agile and non-agile environments, I have to say I like agile, I think if done right for most development environments it has a lot of advantages, the key here is if it’s done right, and for most environments.  If your daily scrum meeting are taking more then 30min, there is strong possibility your doing something wrong.  On the other side with a few exceptions, the idea of specifying every feature your project is going to have before anything is written is, well naive at best.  At the patterns and practices conference Billy Hollis make some comments that really upset a fair number of people in the agile community, and in return they responded with that Billy doesn't know what he’s talking about, etc.  To this my thought was your both right and at the same time wrong. 

Agile doesn't work for everyone, some teams just can’t do it, and that’s ok, you shouldn’t feel bad because your not doing it the way the “cool kids” are, the important thing is to find a development methodology that works for your team.  Having said that, there are a lot of practices that have come out of the agile methodologies that can greatly benefit the non-agile groups, I don’t care what you say unit testing benefits everyone, having a build deploy server helps everyone, etc. 

To the agile zealots out there, agile is A WAY to develop successful and maintainable  software, it’s not the only way.  Lots of very successful projects have been written with non-agile methodologies and lots of very unsuccessful projects have been written using agile.  Everything has it’s advantages and disadvantages, let’s face it the larger your team the harder agile gets.  As in most things zealotry is wrong, I don’t care how good the dogma is, it’s not more important then getting the job done, the most important thing is to get the job done, so find what works for you and do it.

 

Windows vs. Mac vs. Linux/Unix

The OS fan boy wars are a never ending battle between people who for the most part really just don’t get it. So let’s break down the fan boys:

  • Windows fan boys: For the most part they have never used anything but windows, everyone else uses windows so it must be the best at everything so it doesn't matter what Microsoft provides it’s the best.
  • Mac fan boys: Their like the popular kids in school that you don’t understand why their popular because no one really like them that much, and then you add on a devotion that is almost like a cult with Steve Jobs as their messiah.  Some are disillusioned windows fan boys others where born into the Mac fold and all have a limited understanding of what’s out there.
  • Linux/Unix fan boys:  Seeing themselves as elite or ultra power users they look down at windows and Mac users as lower life forms, yet at the same time they are constantly defending their OS.

I must make the disclaimer that I am a former Linux fan boy and to this day I see a lot of faults with windows, but on the flip side I see a lot of improvements that have been made in windows that make it a lot more attractive, but I still really like Linux, funny that I’m a .NET developer.  All three OS have their strengths and their weaknesses and all three work as a development platform, albeit some are better at some development stacks(.NET is easier on windows) and some development requires a specific OS(if you are doing IPhone development you need to have Mac), in all honestly all three work well and it really comes down to what the user likes out of their OS.  I have known some very talented graphic artists that don’t like Macs and have been very frustrated by having to use one, on the flip side I have a Ruby developer friend that really likes Macs.

So in the end it really comes down to is how can we make what we have work for what we are doing, and choosing the right tool for the job, and for who is doing it verses following some techno dogma.

Giving them what they need, verses what they ask for

A little while ago I was contacted to see if I could help an elderly member of my congregation, she needed some help building a mail box post.  The phone call went something like this

her: Do you have a table saw?

me: ya, what do you need?

her: I need to cut up a 4x4 post

me: ok, what are you building?

her: A mail box post and I need to cut some braces at 45 degree angle, you can do that with a table saw right?

me: Bring your stuff over and I’ll help you build it.

This is a perfect example of someone who knew what they needed, but not how to get it.  What she needed was some supports cut with 45 degree angles, and she knew that a table saw could make 45 degree angle cuts, and true a table was could do it, BUT it’s really not the right tool, you’re far better off using a miter saw.

This got me thinking how often we as “tech” have been asked to do something only later to find out it’s really not what they needed or wanted. 

a possible example:

marketing: we need a share point server.

tech: sure, who needs access

marketing: The graphics designer

tech: you want a share point server for one person?

marketing: yes

tech: what is she going to use it for?

marketing: tracking the changes made to images

tech: you want a share point server to track image images revisions

marketing: yes, is there a problem with that?

tech: Let me show you subversion.

This is a very good example of someone having a need and coming up with a solution without consulting with anyone, and asking for the solution without explaining the problem.  In this case I used a marketing person, but this could just as easily be a developer not consulting with operations, or a DBA not consulting with the developers. 

Far to often we are asked to do things with little or not explanation to the problem we are providing a solution for and we don’t ask questions as to what we are solving and this really is a disservice to who we are helping.

Friday, April 2, 2010

The VS2010 Preview

At the local VS2010 Even held in Boise, Id we where given a basic over view of what's in VS 2010, while some of these feature are innovate, like the testing tools, there was a lot of Microsoft playing catch up with some of the other IDEs out there. This by no means is a complete list of what is in VS2010, this is just what was presented at the preview, with a little bit of my commentary added by me.

Team project collection

One of the new features is the Team project collection is TFS, while this sounds great, I fail to see where this is a big step up from other source control systems like clear case, subversion, etc. that have been doing this from the beginning, is this Microsoft playing catch up? or am I missing something.

Project templates

With so many more project types in VS2010 there are a lot more project templates, including Database projects, something to keep in mind is the DB projects only support SQL Server 2005+, sorry SQL Server 2000 people, an interesting side note, you can get a plug-in from Quest software for supporting Oracle.

Extension manager

One of the long awaited features for VS is the Extension Manager, as a user you can manage what extensions you have on your system and browse for new extensions in the online gallery. While I really like this feature, lets face it, Microsoft was really late to the party with this, seeing that most other IDEs (Eclipse, Sharp Develop, Mono Develop, etc ) have been doing this for years.

Multi framework targeting

VS2010 now has multi framework support, now vs2008 did support .NET 2.0, 3.0, 3.5 but under the hood it's still the 2.0 CLR.  In VS2010 you can run code on the 2.0 and 4.0 CLR, this was something the Microsoft reps where very proud of.  Unfortunately this is another area where Microsoft was late to the party where a lot of the other IDEs have been supporting multiple frameworks for years and it get even more prevalent when you get outside the .NET stack.

IDE improvements

The IDE improvements in VS is one area where Microsoft is a leader. Where VS2008 added refactoring tools VS2010 improved upon them, but you're still going to have to pull ReSharper out of my cold dead hand. A quick overview of the IDE improvements in VS2010
  • improved refactoring tools
  • improved debug tools
  • new IDE profiles (environment templates)
  • improved MVC support
  • performance monitoring
  • Local deployment build with end to end packaging for web application
  • improved SharePoint development integration

.NET 4.0 CLR improvements

With VS2010 comes the 4.0 CLR, not only did they improve the performance of the framework they also made strides to make better use of multi core systems.  Lets face it multi threading in general is painful, to solve this .NET 4.0 has an improved threading pooling engine, they now fully support the functional language F# out of the box, and have full support plinq.  Plinq lets you spread the work of a linq Query across multiple cores by figures out at runtime the most optimize query solution.  To use plinq all you have to do is add AsParallel to your linq query and .NET takes care of the rest.

Code Contracts was added to .NET to provide a non language specific way to express coding assumptions. Basically you can specify preconditions, post conditions, and object invariants in order to improve testing via runtime checking and enable static contract verification, how this affects me, I’m not sure yet.

Improved Testing tools

An area that has come a long way in VS2010 are the testing tools, unfortunately some of the more interesting tools are only available in VS2010 Ultimate, but Microsoft did add a stand alone testing product called Microsoft Test and Lab Manager, this lets you do most of your test management with out VS.

Testing features in VS2010:
  • UI testing tools that allow you to code/record UI tests, this looks kind of like the Art of Test (Telerik has a re-branding) tool for Web testing but this supports all .NET UIs
  • Test runner monitors what your testers are doing by allowing you to watch what's going on while testing in order to better track what the testers are doing, this includes customizable data collection to filter out irrelevant data, the ability to add video of how this bug was produced that can be added to the defect tracking system, and displays the step by step test steps to the testers .
  • Virtual system manager (Hyper-V is supported but VMware and Virtual box support is expected post RTM) for setting up and managing testing environments.
  • PEX- automated white box testing tool
  • IntelliTrace is basically a trace and profile tool
  • The test impact analysis tool specifies what test are going to be affected by code changes, for large code bases with lots of tests this allows more targeted testing for TDD.
What you get in the Test Lab and Manager
  • Test case management
  • Create UI tests just like in VS2010
  • Test runner for monitoring what your doing in the test just like in VS2010
  • Can import test cases from Excel
  • Can configure testing data including network connectivity (throttling connectivity )

Team Foundation Server

TFS  has an updated admin tool http://www.codeplex.com/TFSAdmin that generally improves managing your server and users. To better fit in the enterprise level space TFS also added clustering with load balancing and build server pooling; for small shops this may not be that big of a deal but it's nice to know for if and when you're no longer a small shop.

One of the major complaints with TFS 2008 was the build system was painful to use and almost required a dedicated builder, this has been supposedly fixed with 2010 by moving to a work flow based build system, I'm waiting to see if this actually fixes the problem.

An interesting new addition Excel Services integration in TFS.  This allows reporting, updating stories, tasks, test cases, etc. with out having to use the Test lab or VS2010.  The basic idea is the business people can use a tool they are familiar with to interact with TFS. Also the excel service integration doesn't require any CALs to use.

To my disappointment there is not a migration tool to move from other source control systems (subversion) to TFS yet, but supposedly it's on the way, so if you're currently using subversion your going to have to wait.

    Agile Software Development with TFS

    Some of the improvements to TFS are in it's support of agile development, with project templates for agile out of the box and the ability to customize your tickets (they are just xml).  All work items are queryable using Excel Services allowing your product owners and scrum master to know exactly what is going on at any time.

    The build server now supports ATDD (Acceptance Test Driven Development) and tie in UI tests, Unit Tests, Integration Tests, etc.

    An interesting addition is the ability to create a team portal and wiki in Share point automatically. 

    Conclusion

    I'm excited to start using VS2010 all in all I'm impressed with what it dose and how it works.