apache / apache/maven-surefire
[SUREFIRE-2189] Tests in src/main/java are not detected
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
**[Robert Važan](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=robert.vazan)** opened **[SUREFIRE-2189](https://issues.apache.org/jira/browse/SUREFIRE-2189?redirect=false)** and commented
There are sometimes reasons to put JUnit tests under src/main/java next to production code. Surefire cannot detect these tests and runs only tests under src/test/java.
I tried to set testClassesDirectory to target/classes. That causes surefire to run tests under src/main/java, but then tests under src/test/java are ignored. Changing testClassesDirectory also causes weird module loading exceptions in a bigger project with more dependencies.
If you are curious why anyone would put tests in production code, here are my reasons:
1. I want to run all tests in the background after the app starts in dev environment. Since the tests rarely fail, this lets me shorten edit-test-run cycle into edit-run cycle.
2. I want to visually annotate app UI that has associated tests.
3. I want to run tests in production environment as a sanity check.
4. I want to check compatibility between the app and its environment. This could be done with ordinary code, but structuring it as JUnit tests is convenient and results in clean code. I want to run these tests via surefire too to make sure they aren't already failing in dev environment.
5. Keeping tests under src/main/java makes them more salient during development. Tests hidden under src/test/java tend to be forgotten during refactoring or when the tested code changes.
---
**Affects:** 3.1.2
1 votes, 2 watchers
Contributor guide
Research direction
Start by reproducing the issue with JUnit tests placed in both src/main/java and src/test/java, using the reported testClassesDirectory settings and target/classes. Read Surefire's test discovery and configuration entry points; done means tests from both source locations run together without the reported module loading exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100