Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the (dis)advantages of writing unit tests in a different language to the code?

Unit tests have different requirements than production code. For example, unit tests may not have to be as performant as the production code.

Perhaps it sometimes makes sense to write your unit tests in a language that is better suited to writing unit tests? The specific example I have in mind is writing an application in C# but using IronRuby or IronPython to write the tests.

As I see it, using IronPython and IronRuby have several advantages over C# code as a testing language:

  • Mocking can be simpler in dynamically typed languages
  • IronPython has less verbose type annotations that are not needed in unit tests
  • Experimental invocation of tests without recompilation by typing commands at the interpreter

What are the tradeoffs in using two different languages for tests and production code?

like image 663
ctford Avatar asked Nov 13 '09 15:11

ctford


1 Answers

Disadvantages that come to my mind:

  • Depending on the language, you need another development environment (additional dependency of the project, additional effort to setup a development machine, additional licenses, additional training ...)
  • Refactoring is sometimes supported by the IDE - but most probably not for this other language. So you have to refactor them manually.
  • Unit tests can also be used as programming examples. Tests show how the tested classes are intended to be used. This does not work so well if the tests are written in a different language.
like image 143
Stefan Steinegger Avatar answered Nov 10 '22 01:11

Stefan Steinegger