9

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?

plog17
  • 832
  • 8
  • 23
Craig Quillen
  • 2,057
  • 3
  • 23
  • 30

2 Answers2

6

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.

Denis Troller
  • 7,411
  • 1
  • 23
  • 36
  • What sort of issue is there with parameterized properties? – Craig Quillen Apr 29 '09 at 15:21
  • 1
    I am refering to issue 61: http://code.google.com/p/moq/issues/detail?id=61 I don't know if it has been taken care of since it was raised. – Denis Troller Apr 29 '09 at 16:43
  • 4
    _"Contrary to C#, VB[.NET] does not have anonymous methods, only Lambda expressions (no way to declare an anonymous Action delegate)."_ -- I suppose with VB.NET 10 (released with VS 2010 in April 2010), this is no longer true: Now you can write anonymous `Sub`s in-place, even multi-line ones. -- I also disagree with the terminology "lambda expression" vs. "anonymous Action delegate". In both C# and VB.NET, anonymous delegates are fundamentally the same thing as lambda functions; only the syntax may be slightly different. – stakx - no longer contributing Mar 13 '11 at 14:12
  • @Stakx: yes, this answer is indeed an old one :) I guess I should revisit them from time to time. The VB syntax is less conducive to easy lambda/action. As for the terminlogy, I was looking for a way to differentiate a "function" (a lambda expression, since it IS actually an "expression" in the sens that it returns a value which was available at the time), from a "sub" (a single or a collection of statements that do not evaluate to a value in the end, which was not available at the time). C# does not really make a distinction language-wise, but VB does with specific keywords... – Denis Troller Feb 07 '14 at 13:28
  • 1
    So, is Moq now fully compatible with VB? Research on the Internet is difficult due to the problems reported 10 years ago and which keep resurfacing from the searches I make; not sure what the status is as of 2019? – Ama Sep 28 '19 at 12:45
1

AFAIK Typemock Isolator is the only tool that can fully mock VB.NET. They made an API especially for that.