Reputation: 862
I have a project that follows the standard Maven structure:
In some classes, assertTrue is able to be resolved, and in others it cannot be resolved.
I took the static import from the class (in the src/java/test directory) that is resolving and pasted it into the class that can't resolve assertTrue (in the src/java/main directory) and that didn't resolve it.
So using import static org.junit.Assert.assertTrue;
doesn't work.
Using Assert.assertTrue
doesn't work either.
Edit:
One thing that I didn't make clear in the initial post is that this isn't a standard Java project with unit tests. The project is the integration test framework for another Java program. So all the code within this project exists to test the functionality of another program using the external REST API. Hence why I had a Junit assertion outside the test folder. Granted there may still be an opportunity to clean that up.
Upvotes: 1
Views: 1835
Reputation: 862
So the issue was in my build.gradle
file that I had specified the junit dependency as a testCompile
dependency. Meaning that it would only be apply to classes within the src/test directory. So to resolve my issue, I changed the build.gradle to use compile('junit:junit:4.12')
.
I could have also moved the file that wasn't resolving into the src/test directory, but the file didn't logically belong there.
Upvotes: 3