Replacement for Rhino mock - rhino-mocks

Is there a comparable and reliable alternative for Rhino Mock library.
I am using Rhino now for MVC ASP.NET project, but am considering (just as plan B) to see if there are any other equivalent alternatives.

RhinoMocks is a very good and powerful Dynamic Mock library. Even though I have been using it for years, I recently switched to Moq.
To my knowledge, RhinoMocks can do everything Moq can do, and perhaps more. The reason I switched is because RhinoMocks has so many different ways you can do the same thing.
To avoid confusion (particularly for colleagues new to mocking in general), I decided to switch to Moq because it has a cleaner API.

Moq is a very good alternative

I advice moq.

There is also NMock which is very old and I believe uses a lot of magic strings. TypeMock Isolator can do way more (including mock DateTime.Now) but costs money and tends to be used more in hard-core legacy application mocking so it can encourage poor discipline.

Related

Open source AOP library for .NET with no interception limitations

This topic may look like it has been discussed already but I have few more things to say and ask.
The obvious question is; I want to know what AOP library shall I go for a .NET 4.0 enterprise application? As per the post What Aspect-Oriented Programming (AOP) libraries for .NET are still actively developed, one should choose PostSharp or Spring.NET or Microsoft's Policy Injection Application Block. But there are problem with each one.
PostSharp: This is best but not open. I need one whose source is open.
Spring.NET: This is too heavy and has limitations like it can intercept only those classes that is not static, must be non-sealed, properties and methods must be virtual, etc...
Microsoft's Policy Injection Application Block: As per the post Policy Injection Application Block, this is a legacy component now and may stop being supported by MS and since it is implemented through the Unity interception mechanism hence it has same limitation as that of Spring.NET (Alternatives to PostSharp)
I came across the post Aspect Oriented Programming: learn step by step and roll your own implementation!. I have not used it yet but reading through the post gave me an idea that it should serve my purpose. I want to know if anyone has tried it and if it is advised to go for it?
I have one more question to ask; I have used Unity for DI and it is all cool but for AOP, unity is not a good option for my purpose hence I will definitely go for some other tool/library (maybe the one I suggested above!). Is it good to have Unity and something else for AOP in the same application, will there be any problem?
Can anyone please help me here? Thank you in advance!
I think you'll find few good options once you preclude PostSharp and also want to intercept static code.
Some options that you might check out are SheepAspect and Fody, which both take a similar approach to PostSharp (post-compile weaving). Both are very nice and show promise, but are relatively young compared to PostSharp.

Spring-WS 2.0 unit testing without a running backend

I would like to be able to do some unit testing during development in order to catch potential errors when extending/changing the way a given web service (endpoint) works.
I have been looking at EasyMock, and this seems like a viable way to go - but!... I'm using maven (2.0.9) and would like to test e.g. with mvn test, but this requires that my backend is running or that I use EasyMock - which then requires that I can connect to a database (thus this needs some mocking as well). The web services I currently have all retrieve data from a backend base...
As I have 15 or so web services used by different parts of the organization in different versions I would very much like to be able to test that changes doesn't break older versions.
I cannot believe that I'm the first person to have this problem, so any hints, tips, or likewise would be much appreciated.
After comment-based talk :P, it seems that there's no problem actually. The key thing was to understand that some component's dependencies (like database) are just its real implementation dependencies and are not part of its interface. And mocking is about providing alternative implementation, to just satisfy a need for interaction.
In general, as you mentioned, all stuff you depend on in backend need to be mocked (or doubled in general) when unit testing, no matter what this stuff really is. If you depend on some external endpoint, you have to mock it. If you depend on RDBMS, you can mock it too, but probably better test double here would be fake instead of mock, so you can use some in-memory database (like HSQL or H2), assuming you're not using vendor-specific, native SQL in your code. In fact, you're still providing some own, usually simplified implementation of some interfaces, but nowadays you use mocking framework for this. Some time ago, developers write own, hand-crafted mock classes. Even today, it's sometimes really good idea to made own mock without help of mocking framework. Personally I encounter such special situation where this approach fits pretty well.
By the way, two more things. If you consider doing some integration testing as well, Spring WS since 2.0 version provides module spring-ws-test that supports this pretty well by providing really fluent API. For more info look at Spring WS docs, if you're interested. Second thing, if you're just starting with mocking in general, also consider using Mockito. In my opinion, it's really good as well. To be honest, EasyMock is my personal default choice for mocking lib, but I found Mockito similarly easy and powerful. As far as I know, it's prefered by many developers as well and nowadays it's probably more sexy :P.

What are the pros & cons of functional testing frameworks for a new grails application?

I've got analysis paralysis looking at all the different functional testing options for a new grails (v1.3.4) application. I've looked at
WebDriver/Selenium (which I've used before)
WebTest/Canoo
Geb
Tellurium
Grails Functional Test
and there must be others. I think some of the criteria that I would use to make a decision include (in no particular order):
Likely longevity, active development
Can do ajax/javascript
Support for PageObject or similar patterns
Maturity
Headless (eg htmlunit) is ok, especially if it makes things go faster
Good reporting
Support for NTLM credential provider or similar
Compact, robust test scripts
Takes advantage of groovy language
I would be particularly interested to hear from people who have tried more than one framework. Thanks!
I maintain the plugin for WebTest but I'd recommend giving Geb a try. I haven't used it personally on a project yet but I think it will tick off most of your criteria.
It is the most actively developed (IMO) but is quite new. It is built on WebDriver/Selenium so should also be a good fit with your past experience.
WebTest doesn't see a lot of development these days and does not have built in support for page objects. But it does give you great reports. It's downside is it's historical foundation of Ant. It makes it hard to test in a dynamic fashion as your test steps are built up when the test case is executed and then the actual test is run as a second pass.
I have used GFunc as well but the lack of reporting is a real pain and it does not get as much development as Geb. It is far more "groovy" than WebTest though and is a thin wrapper over HtmlUnit allowing you to "roll your own" testing functionality quite easily.
cheers
Lee
Grails Functional Test is HtmlUnit only. I wouldn't suggest coding directly to HtmlUnit these days with the other frameworks that are available that give you page object and better abstraction out of the box.
I've used the webdriver plugin which seems to work pretty well and has page object built in - but the page object support is coupled to the JUnit hierarchy, which makes it hard for me to use because I want to also use Cucumber.
I'm very excited about Geb and am hearing a lot of success stories with it but haven't gotten to finish setting it up myself.

Experiences using moq with VB.Net

I really like the moq mocking framework. I've used it on several projects. Unfortunately, one of my customers is demanding we use VB.Net. Not my preference, but hey, .Net is .Net, right?
I've heard that moq has some trouble with VB. Is this true? Is so, what sorts of trouble? I would expect it to work fine given the language agnostic nature of .Net.
Should I look into using some other mocking framework for use with VB?
The main problem of VB.net with regards to mocking frameworks is that, contrary to C#, VB does not have anonymous methods, only Lambda expressions (no way to declare an anonymous Action delegate).
This severely limits the possibilities.
There is also a known issue with properties with parameters.
Also, the syntax of the language for lambdas does not lead to something as clean as C#, readability-wise (no flames please, I'm a VB user and I miss some C# features every day), and that's partly the attraction for Moq.
The only testing framework I know of that did something with regards to VB is TypeMock. They tried to design something that blends with the VB syntax.
AFAIK Typemock Isolator is the only tool that can fully mock VB.NET. They made an API especially for that.

What is the best mock framework for VB.NET?

What's the best mocking framework syntax-wise and capability-wise ?
My problem: Most mocking frameworks use lambda expressions now, which are really ugly to write in VB.NET, so is there any framework that has nice syntax without lambdas or has fluent syntax that doesn't need lambdas?
I think capability wise Typemock is the best framework for .Net, instead of working within the runtime it hooks into the CLR and can intercept about any call. This enables you to mock and test anything you want. Some people think it's too powerful. It allows you to test anything while usually the fact that you can't test something is a good warning that there's something wrong with your design. Also it's not free.
I mainly use Rhino Mocks. It has a really readable syntax, especially the new AAA syntax. Moq is quite new and should be good too, syntax wise. Although I haven't tested it yet.
rhino mocks.
But you could have trouble with the new lambda-expression syntax (especially when setting expectations on subs) so either use the new syntax or be prepared to work around it.
Typemock's VB APIs are very simple to use, and it has all kinds of functionality like faking Shared functions.
FYI, Isolator has VB.NET specific API so you should be able to use it easily:
http://www.typemock.com/vbpage.php
However, it is a commercial product.