Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize unit tests for a complex class?

Tags:

java

I have a complex class (300+ lines), which I'm trying to test from different "points of view". I've already created three different unit tests. Every test is a complex class itself (100+ lines). The question is -- what is the best place to store them, in project directory tree? This is how I'm doing it now (Maven is used):

pom.xml
/src
  /main
    /java
      /com
        /Foo
          ComplexClass.java
  /test
    /java
      /com
        /Foo
          /ComplexClass
            FirstPointOfViewTest.java
            SecondPointOfViewTest.java
            ThirdPointOfViewTest.java

Of course, the names are just placeholders, used in order to explain the problem/question. What do you think about this approach?

like image 233
yegor256 Avatar asked Jan 22 '23 08:01

yegor256


1 Answers

Your class is so complex that you need three different test classes to test all the aspect of the class? Probably you have mixed too many concerns in a single class. I would suggest refactoring the class using proven design patterns to separate classes with orthogonal concerns that can then be tested individually.

like image 64
Philipp Jardas Avatar answered Feb 01 '23 02:02

Philipp Jardas