I've used TestNG and JUnit. What other frameworks are out there? What makes them special and/or different from the rest?
Java – What unit test frameworks exist for Java
javascalaunit testing
Related Solutions
Generally you will not need to duplicate every unit test. You should identify what is really dependent on the locale (good checklist is here). Many things related to internationalization are subject to the higher level of testing then unit-test.
If you are dealing with the string data that may come in different encodings, then you can utilize "data driven testing", i.e. passing data in different encodings to the same test method. For Java the TestNG is best suitable for this.
Another possible problem is the date/time formatting and parsing. Most locales uses : to separate time elements, but there are ones who uses dots and Brazilians uses h m and s (12h15m30s). This also can be used by passed data in different locales - you do not need to test all of them.
And testing GUI with right-to-left locales is usually not a subject of unit testing.
The bottom line is that you need to identify what data in your unit tests is locale-specific and use data-driven testing (data providers) to supply this data to your tests.
As others have already said, you already have your own, simple, home made framework.
It seems to be trivial to make one. However, there are some other features of a unit-test framework that are not so easy to implement, because they take some advanced knowledge of the language. The features I generally require from a test framework and are not so easy to homebrew are:
Automatic collection of test cases. I.e. defining new test method should be enough to get it executed. JUnit automatically collects all methods whose names start with
test
, NUnit has the[Test]
annotation, Boost.Test uses theBOOST_AUTO_TEST_CASE
andBOOST_FIXTURE_TEST_CASE
macros.It's mostly convenience, but every bit of convenience you can get improves the chance developers will actually write the tests they should and that they will connect them in correctly. If you have long instructions, somebody will miss part of them now and than and perhaps some tests won't be running and nobody will notice.
Ability to run selected test cases, without tweaking code and recompiling. Any decent unit-test framework allows you to specify which tests you want to run on command-line. If you want to debug on unit tests (it's most important point in them for many developers), you need to be able to select just some to run, without tweaking code all over the place.
Say you just received bug report #4211 and it can be reproduced with unit test. So you write one, but than you need to tell the runner to run just that test, so you can debug what's actually wrong there.
Ability to mark tests expected failures, per test case, without modifying the checks themselves. We actually switched frameworks at work to get this one.
Any decently sized test suite will have tests, that are failing because the features they test were not implemented yet, were not finished yet, nobody had time to fix them yet or something. Without ability to mark tests as expected failures, you won't notice another failure when there are some regularly, so the tests stop serving their main purpose.
Best Answer
Scala Specs gets my vote! :-)
Specs is a behavior-driven-development testing framework written in Scala. It can be used to write tests for Java and Scala. It was inspired by RSpec - a testing framework very popular in the Ruby world.
An example test written in Specs:
Impressive, isn't it? :-)