views:

227

answers:

4

In the past I wrote most of my unit tests using C# even when the actual software development was in another .NET language (VB.NET, C++.NET etc.) but I could use VB to get the same results. I guess the only reason I use C# is because most of the examples in the internet are written in C#.

I you use unit tests as part of .NET software development what language do you prefer to use and what is the reason you choose to use it?

I know that it depend greatly on the language of the proect under test but what I'm interested in finding out is whether there is a preference of a specific language to use while unit testing.

+1  A: 

I write all my .Net application/business code in C#, so it is quite natural to write the unit tests in C# as well. I think that writing the test code in another language introduces an unnecessary separation between the test code and the application code.

Erik Öjebo
So if would have to test VB.NET you would write the tests in VB?
Dror Helper
Yes, personally I would try to keep the test code in the same language to keep it as easy as possible to switch between writing test code and application code.
Erik Öjebo
+5  A: 

You should use what ever language is comfortable for your dev team.

I don't see what you would write your unit tests in a language other than the language that the rest of the project is written in as it would have the possibility to cause confusion, or require devs know two different languages to work on the project.

Tests should follow the KISS principle.

Slace
Have you ever written unit tests in lsnguage other than C#?
Dror Helper
+1 for KISS principle, tests are there to make things easier, understandable and maintainable.
dove
No, we're a C# dev house so it is illogical to introduce a language other than C# for the purpose of unit tests. Doing the tests in VB (for example) would offer no advantage, and it would hamper future dev work
Slace
+2  A: 

C# because that is what all new code base is being written in. I would say it largely depends on what the companies preferred language is. If possible I think it best to fix on one if possible and this would also be what tests are written in too. And if only a few write in C++ then keep the more common languages still as tests so more could work well with them.

dove
+1  A: 

I almost always write my unit test in the same language that I am developing the application. I don't really have a reason for this other than it seems like the most logical idea. I can program in a variety of languages but that doesn't meet the person picking up the code after me can.

I do have one exception to that. When I code in F#, I often write the unit tests in C#. Namely because the IDE doesn't support F# unit tests very well.

A secondary reason is that Unit Tests often times are not great code. It can require some akward setup from time to time to test corner scenarios. In that situation I often find that F# type safety makes it hard to test that scenario. It's probably just my lack of experience with F# but I find it easier to create these scenarios with C#.

JaredPar