mercredi 31 août 2016

JUnit - How many files for testing a single class?

Let's say I have a class MyClass.java and we have to write a tests for it. Some of them will execute once, some of them will execute multiple times.

  1. I prepared two test classes - MyClassTestSingle.java for single tests and MyClassTestMultiple.java for tests with @Parametrized annotation.
  2. I wanted to run them from a single file so there is another class - MyClassTestSuite.java.
  3. In MyClassTestSingle.java and MyClassTestMultiple.java methods I use same parameters with a same values so i started thinking about a class containing these parameters...

But then I realized I wanted to create four classes for testing a single class. So I started looking for some "good practices" how to keep my test classes clean and simple. But found no worthy informations about number of classes I need when writing tests for a situation above.

I started thinking that maybe there is a design problem in my MyClass.java, but for sure there are situations when there is need to make a parametrized and single tests and then pack them into a suite.

Am I wrong? Or maybe I just don't understand something?

Aucun commentaire:

Enregistrer un commentaire