Showing posts with label tools. Show all posts
Showing posts with label tools. Show all posts

Wednesday, 4 July 2012

Instoolation

Instoolation (n): belief that process problems can be solved by installing a tool. Gojko Adzic, BDD: busting the Myths.

I see that mistake more and more everywhere I go. During last Iltam meeting Elad gave a talk about tools for agile project management and the general spirit of the audience was, we have all sorts of thing we need to solve and we expect a good tool to help us solve those. things like dependency tracking, risk management, predictability, traceability, and more.

there is no tool that will solve any of those problems, you first need to install a good process that address those problems and later on you might be able to use a tool to help you to reduce the effort you invest in the solution.

but actually I didn’t want to write much about that, I do want to discuss about what happens when you add another deadly ingredient in the mix:

Not Invented Here (NIH) – Syndrome

From Wikipedia:

Not invented here (NIH) is a term used to describe persistent social, corporate, or institutional culture that avoids using or buying already existing products, research, standards, or knowledge because of their external origins.

So what do you get when you cross an Instoolation disease with the NIH syndrome?

Right. A huge chunk of money that goes down the drain to develop an in house tool that aimed to solve a problem that can’t be solved by a tool.

Just to give an anecdotal example, in one of my past work places, I experienced a 5M$ budget goes into customizing an existing ALM tool which was then assimilated into the company over a period of about 2 years and with extreme pains. The fun part was once the project was “successfully” completed,the involved team was immediately taken to do a proof of concept on replacement tools since the developed system was considered wasteful.

It just pains me to see companies going that road.



Want to adopt Agile and don’t know where to start?
click here to learn

Tuesday, 24 May 2011

Exporting Code Metrics from Command Line

A couple of months ago Microsoft released a tool enabling to gather code metrics on code form command line. (detailed post here).

While it took me some time I’ve updated my Msbuild custom tasks project and added an Msbuild task for better integration of the tool into a build cycle.

The task enable the exporting of metrics for a given solution and includes an xsl to transform the resulting xml into an html report.

(older tasks in the project allowed running all tests (using mstest) in a given solution and exporting VS coverage report to an xml)

To download the latest release go to here, and if you have any questions or additional requests contact me either through the CodePlex forums or directly.

Friday, 11 March 2011

Reflector is no longer free

Yesterday, after several year of supporting reflector RedGate has turned it into a commercial product in releasing a new paid version (v7) taking down the free download. Naturally there is an uproar in the community about this move. What ticks most people is the fact that inside older versions of reflector there is a time-bomb causing reflector to delete itself unless you upgrade to the newest version.

While this time bomb was inserted along time ago (before it was picked by red-gate) the original intent was to make support easier by making sure only newer version of the tool was out there. Now this mechanism means that the free version can no longer be used.

While the price for the standard license is quite low (35$), my believe is that Red-Gate is now facing a public relationship hell, and so far their response has only made things worse. Red-Gate people only response so far was to either point out that this was an old mechanism, and the regular "we wish only to make things better", so far no actual direct response to any of the claims made by the community (here's an example thread - notice Greg Tillman answer)

Being a long user of reflector there's a good chance I'll purchase it however before I do that, it seems that alternatives are starting to pop around:

ILSpy

A new open source tool part of the SharpDeveloper IDE. I haven't tried it yet, but looking at the screencast it looks fairly similar to what I use reflector for, so this would be something ill certainly try.

keepdecompilingfree.com

Another interesting site i stumbled upon is this site http://www.keepdecompilingfree.com/ rumors claims that JetBrain might be involved, but so far I wasn't able to find any solid evidence for that. Knowing JetBrain, I do hope that there is some truth into this.

Tuesday, 8 February 2011

Exporting Code Metrics VS 2010

At last Microsoft released a Power-Tool to enable generating Visual Studio 2010 code metrics analysis using a command line.

the tool can be downloaded from here:

Visual Studio Code Metrics PowerTool 10.0

The output is stored into an XML file which is than can be processed to generate a nice visible report.

Next steps would be to create an xsl that can be used by various build servers (like cc.net).

and integrate this into the crap4Net tool so it can process that format.

This is going to be be useful.

Sunday, 15 August 2010

Running all Tests in Solution

MsTest is a nice testing framework. However it can be annoying from time to time. a while ago in the past I’ve blogged about the inability of this testing framework to execute all tests in a given sln file.
Recently i had some time and I decided thats its about time that ill do something productive about this (instead of my usual complaining) and I’ve sat down to write a simple msbuild task that runs all tests in a solution.
here is an example of a build script that uses this task:
<UsingTask
 TaskName="RunAllTestsInSolution"
 AssemblyFile="RunAllTestsInSolution.dll" />

<PropertyGroup >
 <MSTestLocation>C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE</MSTestLocation>
</PropertyGroup>

<Target Name="UnitTestsWithCoverage">
 <RunAllTestsInSolution
   MSTest ="$(MSTestLocation)\mstest.exe"
   SolutionFile="Example.sln"
   Parmaters ="/resultsfile:TestResults.trx" />
</Target>
As you can see you just tells it which mstest version to use, the solution file containing the test you want to execute and any additional parameters if needed.

You can download the source code from here.

*UPDATE*
There is a CodePlex project containing an updated source code along with a couple of  other useful Msbuild tasks. Here's the link

Wednesday, 14 July 2010

Unlocker is Back

One of the most useful development tool I used in the past is Unlocker. this amazing tools is a life saver when you are developing using the file system and use may cause all kind of file handler to be left hanging.

however about a couple of years ago (I think), when I was forced to switch to working on a 64 bit vista machine, I stopped using it since it didn't support that platform.

You can imagine my happiness when found out this week in the Alt.NET tool evening that they now have a version that does support my configuration.

Who said that conventions are a waste of time?

Sunday, 16 May 2010

Showing GoogleTests/JUnit Results in CC.Net

In a Place I’m working in, we needed to integrate the results from tests running in the C++ googleTest framework into the team build machine which is running CC.Net.

It appears that GoogleTest can output its result into a standard JUnit xml format, however I couldn’t locate a proper XSL that will transform the results into a nice report in the CC.Net Dashboard.

The following link points to the resulting xsl file that will create a nice looking report from googleTest output.

  1. Instruct googletest (using the –gtest_output) to write its result into an xml.
  2. Update the ccnet.config file to merge the resulting file into the CC.Net build report.
  3. Put the supplied xsl into the webdashboard/xsl directory of the cc.net installation. Download the xsl from this link.
  4. Update dashboard.config file to use the given xsl.

Hope this will save some time for somebody.

Thursday, 28 January 2010

Quick Unit Video

After several tries I managed to finally upload the Video from last night session. here is the link.

(BTW the Lecture is in Hebrew)

Wednesday, 27 January 2010

Alt.NET Israel - First tool night

altdotnet

Just came back from the first Alt.NET tool night and it was fun.all and all it was quite long. We had 6 short sessions (15-20) minutes along with a short break so it ended about 21:30.

The sessions themselves were quite interesting and covered a wide variety of tools. the good news is that the entire session was filmed by Ohad Israeli and I'm sure he will upload it in a few days (probably tomorrow).

I did however brought my own camcorder and managed to film the session about Quick Unit.

For those of you who are not aware, Quick Unit is a new test authoring tool, which speed up the process of creating unit tests along with giving guidelines on how to write them properly. Unlike other test generation tool, the basic idea is not to try to create many test cases that covers the entire code, but is more like a designer for test, much like a standard UI designer.

Anyway I've downloaded the tool and will give try it out properly in the next couple of weeks to see how does it help me. So be prepared for a follow up . In the mean while I'm currently uploading the film to the web and will publish a link first thing tomorrow morning.

Sunday, 15 November 2009

Is Typemock Isolator Evil - Round N+1

Every few months the argument for and against the advance abilities of the Isolator mocking framework burst again. This time it started with this post: Test driven design – Willed vs. Forced Designs

Disclaimer: I used to work for Typemock company and was in charge for a long time over the development of the framework. so I claim no kind of objectivity .

the argument for and against usually circle around the following:

on one side, people claim that Isolator "breaks" the language barriers and, by allowing any kind of design to be implemented will end up in helping to build a poorly designed system.

on the other side, by allowing the freedom to design at will Isolator shift the responsibility back to the developer allowing him to choose the "best" design as he sees fit.

here are some points I want to comment on:

If you need Isolator you have a bad design

Actually that one is in most cases true. However the following claim "you have bad design" also holds for too many cases as well. Yes I'm saying that most systems out there are poorly designed. I'm also saying that most software project out there will fail. What I don't like about the initial claim is the conclusion that usually follows:

If you need isolator when you have poor design, usage of isolator will end up with a poor design.

That statement is plain wrong, you will end up with poor design unless you learn how to design better. The effect Isolator (or any tool for that matter) will have on a team design skills is minimal at best. Pragmatically speaking if you are are working on a legacy system isolator is probably the better choice no matter what. If you are working on a newly project and you just start out TDD, most likely using isolator will increase the chances you'll be able to stick with it. (adding the need to relearn design at this stage is soo much harder), and if you're working on a new project and you do know how to TDD. Then you should just know better and be able to safely use the tool. If you don't then you really do have a problem.

Isolator breaks the natural barriers of the language

Yes it does, but the statement "Statics are the death of testability" which actually means "don't use static methods" adds barriers to the language which is not there. so what's the better approach? again I don't know. It really depends on your personal preferences and has nothing to do with what is the best design

Actually there's no such thing is the best design. Every design must evolve always to fit the system needs.

Show me a concrete example

example number 1:

many systems have a dependency on the time of day. the naive way to approach that is to use DateTime.Now. but oops that one cant be faked (its a static method) making it a real pain to test. so experienced programmer introduce the ITime interface wrapping the system time with an interface and then adding some concrete code to make it work, all for the sake of testability. here's an example taken from the testify project on how to implement this:

public static class SystemClock {

private static DateTime? fixedTime;

public static DateTime Now {
get {
if (fixedTime.HasValue)
return fixedTime.Value;
return DateTime.Now;
}
}

internal static void Set(DateTime value) {
fixedTime = value;
}

internal static void Reset() {
fixedTime = null;
}
}
Please enlighten me as why this is better/simpler as opposed to use of DateTime.Now.


example number 2:

I have a class A depends on Class B. Class B is the ONLY concrete class implementing the interface ISomeInterafce (and most likely this will hold true forever). Class A is the only place (for now and most likely forever) ISomeInterface is used. yes this is a simple example but since I'm inventing it, I get to set the rules.

and there are several ways to approach this:

1. Use some IOC container to instantiate B and send it to A. a valid OO way with many benefits however in my concrete example (and yes I'm the one setting the rules). I don't have a true need for a full pledged IOC yet, and this very simple scenario wont be the one causing me to start using an such a big hammer

2. Use a factory - a simpler version of the IOC container idea, much more light weight. but still at this point of time (and yes I get to make the rules) under the specified circumstance it falls under the YAGNI directive. If the situation changes (i.e. more places will use ISomeInterafce or more "kinds" of ISomeInterafce will evolve) a factory will be used but for now I don't really need that.

3. Instantiate B somewhere and pass it into A (the simplest form of DI) - a very simple solution which is valid under this scenario. the down side for it are , that it exposes some inner working details of A which may not be a good idea AND most likely it only shifts the problem to someplace else.

4. Just use a new statement somewhere inside A (lets say constructor) - I like this way. Its the simplest thing that can possibly work, and I'm not tied to the "design for testability" chains, so I can do that. and just before I get chopped, yes taken outside this context of this simple concrete example is most likely not a good strategy.



I want to make the Choices. I'm the professional trained to do them. I wont stand being TOLD how to do my job, not by a person, and especially not by a tool.

Thursday, 29 October 2009

Gathering worthwhile feedback

Tobias Mayer has got me (and I guess several other) thinking about the common feedback process used by trainers. While I think that there's much to learn from the general purpose form handed out at the end of a training, clearly doing it only at the end of a training session means you cant use it for improving during a lengthy course.

Therefore I use two different techniques for gathering feedback during a course

Course Retrospect

this is actually quite simple and effective technique, towards the end of the second day. usually after I cover the sprint retrospect meeting. I conduct a short "retrospect" meeting with the aim of improving the actual course. My current favorite way is borrowed from Alistair Cockburn and we try to list out (together in an open discussion) the things which are:

  1. Going good for us so far,
  2. causing issues and difficulties,
  3. and things that we want to try to do different on the next day.

That way not only do I gather feedback that I can use to improve on, we also get the chance to practice and witness the power of Sprint retrospect meetings.

Guided Questions

The second technique I'm using was inspired by Roy Osherove, and its a little more subtle. The basic idea is to ask a few (usually 2) open ended questions regarding the passing day. For a concrete example read these 3 posts: day 1, day 2 & day 3.

And this works really well. First, asking these question at the end of the day makes people go over and reflect on what they have learnt during the day. It take 5-10 minutes in which I see them going through the written material trying to fish out an answer. Just for doing this I think its a great practice. Second, I really learn a lot about how they grasp Scrum, what are the main difficulties, what is seen as beneficial, what they think will be easy and so on. And last in most cases the answers show me how well I did as a trainer. For example on the first day I got an answer saying that "Documentation is not needed." That was not the idea I was trying to convey (In fact I clearly specified that "its not that documents are not needed...." at least twice) therefore I need to improve on that (clearing that point again on the following day).

Both technique are simple, quite fast (takes between 5-15 minutes) and results in good feedback. combining them with the general purpose feedback form really works great for me so far.

Sunday, 18 October 2009

More Information about C.R.A.P

More details about the usage of C.R.A.P and what C.R.A.P is all about can be found in the following links:

  1. Metrics of Moment
  2. Clean Code and Battle Scarred Architecture
  3. Alberto Savoia talks shop about C.R.A.P.

Crap4Net

Measuring code quality is a tricky business at best. More then a few attempts has been made over the years however still a single solution has yet to emerge. The C.R.A.P metric has been born a few years ago and tries to combine code complexity along with Code coverage to indicate (to some extent) the quality of a given piece of code. There’s much more to say about the C.R.A.P metric which ill leave for the experts . I will say however that more information can be gathered in the Crap4J website.

Over the last weeks I have been working on creating the Crap$Net project. The Idea is to bring the C.R.a.P metric into the world of .NET development by supporting the various tools used in this world.

I am happy to say I managed to wrap this effort into an open source project which was published today over at CodePlex, you can view the project home page here.

For now the tool is able to take the resulting xml reports generated for Code coverage and for Cyclomatic Complexity and generate a single XMl containing the C.R.A.P data. nothing too fancy but for starter this should do. the tool currently supports Coverage data generated by PartCover or by MsTest internal coverage tool . Cyclomatic Complexity data is generated by using the Code Metric add-in of Reflector. What was important to me is the ability to take this tool and plug it into a continuous build cycle and less the visibility of the data.

Future plans span two mains directions, the first is to include support of other coverage tools (if you have any preferences please leave me a comment) and if needed other formats of Cyclomatic Complexity reports. the second is to add some more fancy reporting which will include a basic html summary and maybe even some more stats on the underlying code.

So if you ever wondered how Crappy is your code, done wonder just download and get an answer.

Tuesday, 13 October 2009

Iteration Zero – using Testify

One approach when starting out a new project is to dedicate the first sprint/iteration in order to build in the framework for the development process. that is building in all the stuff which will be required during the time life of the product. things life setting up the build server, preparing the installer establishing the framework for unit and acceptance testing. in short all the technical details an agile development environment expect to just be there.

Today I managed to go into Mike Scott session in which he demonstrated his very nice tool called “Testify”.

I don't want to go into all the details since it appears that just today Mike has finished to ‘open source’ the tool. (can be found here). I would however say that during the short time in the session (about an hour), Mike has managed to create a new project which contained :

  1. Some source.
  2. Executable Unit tests (using NUnit)
  3. Executable Acceptance tests – using fit
  4. Setup a source control repository (Subversion based)
  5. and Setup a continuous build server (using CC.Net)

Since I have done this kind of things a couple of times. i was really really impressed.

Thursday, 3 September 2009

Running all tests in solution using MSTest

There aren't many times I truly have something bad to say about MS. Its not that I'm a great fun, but I admit that in most cases they do get the job done (it just takes a couple of tries though).

However, there is one thing that always tick me when working with MS products and that their ability to create product which doesn't work well with anything else besides other MS products. Normally I'm not into conspiracies and would of written it off as simple mistakes, but I'm guessing I just have to much respect for MS developers.

And the thing is that this always happen at the really annoying small things when you least expect it, but when encountered really make you go *#*#*!*!$*!*#!.

and the story goes like this:

At one of my clients I'm helping setup the build server to run all the unit tests the development team is going to write (which is why I was brought in at the first place). After some initial work in configuring CC.Net (which didn't take long at all), I've wanted to add the unit test execution part. so I went on to search for a way to execute all tests in a given solution. Shouldn't be too hard right?

Well WRONG!

After touring the web for some time it appears the Mstest has, how unconventionally, left this somewhat trivial ability out of their tool set (they didn't forgot to put a button in the IDE for doing so). its easy enough to do it if you use TFS as your build server solution, but using anything else means that one need to feed MSTest command line with all the various test dll's explicitly and MANUALLY!

so here are some other options:

1) Taken from Stack Overflow (towards the end) - a way to semi automate this using msbuild based on some naming conventions.

2) MSTest command line can use the vsmdi as their execution input, so one can simply create a list with all existing tests and use that. However now one need to maintain that all knowing list.

3) write up a small utility which based on the data inside the sln file, produce a list of all tests dll's - shouldn't be too hard but who would like to do that?

and the last thing (which i think i will choose at the end )

4) kind of a brute force, but if MSTest can only receive one dll as input, lets give him one. And I'm not actually talking about actually writing all the unit tests inside a single DLL. I'm thinking about using ILMerge to consolidate all DLLS in a given output directory (production and tests) into a giant DLL and feed it into MSTest. (I just hope that it will be able to process that dll)

Really Really ANNOYING!!!!!

Sunday, 21 June 2009

Versioning Scheme

There are various scheme for handling version number. But so far I haven't really encountered anything meaningful in any of the schemes. several days ago I encountered scheme which I really liked.

The scheme is a variant of Change Significance and is specifically aimed for API libraries, that is while I'm sure it can be extended to regular products, its basic semantics is for aimed for API's libraries.

and the semantics goes like this (using a four digit sequence):

  • a change in the first number means the API has changed in a breaking manner.
  • a change in the second number means there were additions to the API
  • and a change in the third number means an that the internal behavior
  • Last number is a sequential build number.

Let take for example NUnit, if NUnit will adopt this scheme. When upgrading from lets say 2.4.0 to 3.0.0, I would expect that some of my existing tests will need to be updated to reflect the changes. When upgrading from 2.4.0 to 2.5.0, I would expect to see some new abilities reflected in new API's (but my existing tests should still stay valid). And last, when updating from 2.5.0 to 2.5.1 there would be some internal changes in behavior that shouldn't affect me at all.

I really liked this one when I heard it, what do you think?

Sunday, 15 March 2009

NUnit Extensions - Adding Logic at Run Start

Most of the time using NUnit is very straight forward. Recently however I needed to add some functionality that will make life a little bit easier. In this post I'll show how to add some setup code that will be executed once at the start of the test run.

Why is this useful? actually I don't have a clear answer. Here are some reasons I came up with :

  1. Run some special set up code which is just to costly to run at every setup (even if only for class setup).
  2. Transparently enforce some logic on all tests (i.e. without the need for other programmer to explicitly add that logic)
  3. you want to add some special behavior to the test runner

 

NUnit Event Listeners

NUnit has several extension points that will adding almost any kind of logic to the framework. Ben Hall has posted some time back a great article describing the various possibilities For my needs (which are described here) I have been using the Event Listener extension point. Here's the class implementing the event listener:

[NUnitAddinAttribute(Type=ExtensionType.Core,Name = "My Add In",Description="A Demo for Run Setup Code")]
public class CTestingAddin : IAddin, EventListener
{
#region IAddin Members

public bool Install(IExtensionHost host)
{
IExtensionPoint listeners = host.GetExtensionPoint("EventListeners");
if (listeners == null)
return false;

listeners.Install(this);
return true;
}

#endregion

#region
EventListener Members

public void RunStarted(
           string name, int testCount)
    {
//Do Set up logic Here
    }
    public void RunFinished(Exception exception)
{ }

public void RunFinished(TestResult result)
{ }

public void SuiteFinished(TestSuiteResult result)
{ }

public void SuiteStarted(TestName testName)
{ }

public void TestFinished(TestCaseResult result)
{ }

public void TestOutput(TestOutput testOutput)
{ }

public void TestStarted(TestName testName)
{ }

public void UnhandledException(Exception exception)
{ }

#endregion
}

Deployment and execution

That's all the code needed and it can be wrapped as a simple class library (dll). The dll created will need to reference the nunit.core and nunit.core.interfaces. To deploy just copy the dll to the NUnit bin\addin directory. To verify it was properly deployed open the NUnit GUI and check the tools menu under add-in to see that the add-in is there.

I will finish with two tips that will make life easier to run and debug the code.

  1. Its worth while to add a post build event that will deploy the add-in in into NUnit directory at the end of a successful build. In order to do that open the add-in project property and the following to Post build Event Command Line: copy $(TargetPath) <NUnit Directory>\bin\addins.
  2. A convenient way to debug the add-in is to put the NUnit GUI as the "Start action" of the Add-in project. This will enable putting break points normally in the code. (another option is to use the Attach To Process mechanism Ben has suggested).

Tuesday, 3 March 2009

Collection Asserts in MSTest (and some more)

Sometime I can miss the obvious.

I've been working with MSTest framework for over a year now and up until today I completely missed the fact that beside the Assert class MSTest framework contains 2 other assert classes :

  1. StringAssert - used for string specific asserts like StartsWith, EndsWith and even support regular expression matching
  2. CollectionAssert - used for collection operation like Contains, AllItemsAreNotNull and the most useful AreEquivalent.

Naturally NUnit also has equivalent classes (which of course I missed as well).

Now the thing that really ticks me off is that I was asked this specific question twice in the last month and gave the wrong answer. Only today after I allocated 2 minutes to actually google it, I found out about it.

Lesson learnt - For all consultant out there, Don't get overconfident about your knowledge. Even if its in you specific area of expertise. Always assume that you are mistaken and double check your answer (especially if your answer starts with "You cant...")

Sunday, 1 March 2009

Sela Open House

Last week I gave at Sela a lecture about Design For testability.  For all those who attended I want to thank you for coming.

For all those who missed it, you might be able to catch it this week (I'll be giving it again at Sela on Tuesday) or if you happen to be located at the north parts of Israel it will be repeated nearer to you on the 25/3.

For everyone else you can get the slides here.

Sunday, 8 February 2009

WPF Testing - Part I

Automating GUI testing is always a tricky business. In fact its so hard that people tend to mark it off as too hard to bother with. I believe however that this observation is not correct.

During one of my consulting gigs I was starting to instruct a new team on the concepts of unit tests and since they working on a real product they actually have some GUI involved (imagine that).If that's not enough they are using WPF as their framework of choice. I on the other side cant claim to be a GUI expert (to say the least) and my hands on experience with actual WPF code is, well, close to nothing.

I couldn't leave it at that, so I invested some time in actually trying to figure out how one can write tests for WPF based GUI. This post (which hopefully will be followed by some more) will demonstrate my finding on the matter.

First scenario I wanted to test was how I can trigger an event using code instead of a person clicking on the GUI. For that (and probably for the following examples as well) I constructed a small application that looks like this:

mainWindow

As you can see for now I have a big empty window with a single button and some text fields, but for now hat will be enough. In order to achieve what I'm doing I'll be using the Isolator framework, and I will try keeping my design as simple as I can (I know that there are many patterns out there that probably reflect a much better design scheme, but I really like to address the pressing need of the common programmer and not resort to fancy designs patterns at this point)

Firing a mocked Event

As I said, first I want to explore how to test an event handler wired to a button. i.e. to simulate a user pressing a button and check that the correct logic is executed. for the purpose of this demo I assume that my GUI is backed up by a business logic layer that will handle the actual business logic, and since that should be tested separately,  all I want for now is to make sure that the proper logic from that layer is called.

so here's the implementation of the business logic:

internal class BusinessLogic
{
void GetResult()
{
throw new NotImplementedException
("no logic yet");
}
}
As you can see noting much in there, in fact since I'm not interested in the buisness layer at this point the implemantation is not yet ready and all i have is a an empty

and here is the the window source code:

public partial class HurtFundsMainWindow : Window
{
public HurtFundsMainWindow()
{
InitializeComponent();
}

private void GetResults_Click(
object sender, RoutedEventArgs e)
{
BusinessLogic logic = new BusinessLogic();
logic.GetResult();
}
}

Again at this point i dont have much, only a simple event handler for the button click action that will delegate all logic into the business layer. Note that i'm not using any dependancy injection pattern and I'm not working against an interface at this point. (my application is so simple that I really don't see the need for doing that. I assume that when the application evolves the need will make me evolve the design as well)

and here is the actual test code:

[TestMethod]
[Isolated]
public void Clicking()
{
//Create the fake business logic and inject it into production code
BusinessLogic fakeLogic =
Isolate.Fake.Instance<BusinessLogic>();
Isolate.Swap.NextInstance<BusinessLogic>()
.With(fakeLogic);

//Create the fake button
Button fakeButton =
Isolate.Fake.Instance<Button>(Members.CallOriginal);
//inject it into production code
Isolate.Swap.NextInstance<Button>()
.With(fakeButton);
//replace the button event wiring
Mock mockButton =
MockManager.GetMockOf(fakeButton);
MockedEvent handle =
mockButton.ExpectAddEvent("Click");

//create the window
HurtFundsMainWindow wind =
new HurtFundsMainWindow();

//fire the mock event
handle.Fire(wind, new RoutedEventArgs());

Isolate.Verify.WasCalledWithAnyArguments(
() => fakeLogic.GetResult());
}

Not very trivial so lets see what's goes on here.

the first step in the test, is creation of the fake business logic, i create the fakeLogic and using the Swap ability I ask the Isolator framework to replace the next created instance of business logic with the fakeLogic (check this for further details).

Second step is doing the same for the button that will be created, after that I also fake the actual event wiring done by WPF and put my hands on a faked handle which I later use to fire the event. (note the event handling is done using an older variant of the Isolator API. I hope that in the near future the proper API will be added to the AAA syntax as well)

Next comes the actual executing. I first create the window, and then I use the fake handle to trigger the event.

At the end of the test I verify that the GUI actually calls the proper logic method (in this case the GetResult() method).



That's all for now, while this is only a basic scenario, the principles shown here can be adapted to handle much of the event system of the WPF system. If you have any questions feel free to leave a comment.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Walgreens Printable Coupons