Relationship Between Test and Production Code
Explore the interaction between test and production code in Java projects using JUnit. Understand best practices for organizing tests, including directory structures and package arrangements. Learn the implications of exposing private data and behavior in tests and how this relates to software design principles like the Single Responsibility Principle. This lesson helps you write maintainable tests while supporting better production code design.
Exposing private behavior The JUnit tests we write will live in the same project as the production code that they verify. However, we’ll keep the tests separate from the production code within a given project. We’ll be shipping the production code (the target of the tests, sometimes known as the system under test or SUT), but the tests will typically stay behind.
Unit testing is solely a programmer activity. No customers, end-users, or non-programmers will typically see or run our tests.
Uni-directional testing
Unit testing is a one-way street. Tests depend on the production-system code, but the dependency goes only in that direction. The production system has no knowledge of the tests.
That is not to say that the act of writing tests can’t influence the design of our production system. The more we write unit tests, the more we’ll encounter cases where a different design would make it easier to write tests.
... ...
Tip: ...