Pre-check
- [x] I am sure that all the content I provide is in English.
Search before asking
- [x] I had searched in the issues and found no similar feature requirement.
Apache Dubbo Component
Java SDK (apache/dubbo)
Descriptions
The Key Problems of Unit Tests that Use System.* Calls (like System.out.println
)
1. Violates unit testing best practices (test isolation principle).
2. Causes thread blocking due to synchronized I/O operations.
3. Slows down parallel test execution.
4. Makes test output harder to track.
Recommended Refactoring Approaches 1. Remove these codes from unit tests, at least most of them. 2. Replace System.out.println with proper slf4j/Log4j2 (perfered) if the test info is very very important. 3. For validation needs, use assertion libraries.
Examples
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class MyTest {
private static final Logger logger = LoggerFactory.getLogger(MyTest.class);
@Test
void testMethod() {
// remove System.out.println("test info") or log the test info if needed.
logger.debug("Debug info: a={}, b={}", a, b);
// Actual test assertions...
}
}
Additional Recommendations If Log the Test Info
1. Configure log levels appropriately (DEBUG/INFO) if log the test info.
2. Use parameterized logging to avoid string concatenation. (like logger.info("my info={}, {}", a, b);
)
Related issues
No response
Are you willing to submit a pull request to fix on your own?
- [ ] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct