Hey, I have a problem with Junit, can someone help me with the code ?

No description
26 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @Allan! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st4mo ago
Can you show your dependencies? How are you running the tests?
huggy wuggy
huggy wuggyOP4mo ago
okay wait
huggy wuggy
huggy wuggyOP4mo ago
No description
huggy wuggy
huggy wuggyOP4mo ago
No description
huggy wuggy
huggy wuggyOP4mo ago
No description
Crain
Crain4mo ago
sourceSets {
test {
java {
srcDirs = 'src'
}
}
}
sourceSets {
test {
java {
srcDirs = 'src'
}
}
}
@Allan
huggy wuggy
huggy wuggyOP4mo ago
still not working
Crain
Crain4mo ago
In that case we'll swap to the more traditional approach, let me knab a screenshot
Crain
Crain4mo ago
This is the traditional approach in Java Projects, we don't really do test files next to implementation files like you might see in TS/JS land.
No description
huggy wuggy
huggy wuggyOP4mo ago
yeah but when I add module test it creates another main in the src
Crain
Crain4mo ago
You aren't creating another module Just a directory
huggy wuggy
huggy wuggyOP4mo ago
so I have to create a directory test in the src and is java a directory or package
Crain
Crain4mo ago
Not in /src, in your case it would be in the root Both are just folders They only look special because of IntelliJ You also need
test {
useJUnitPlatform()
}
test {
useJUnitPlatform()
}
In your build.gradle
huggy wuggy
huggy wuggyOP4mo ago
okay wait yeah but when I create a test directory out of src and create a java directory in the test directory then it doesn't recognize the imports
huggy wuggy
huggy wuggyOP4mo ago
No description
huggy wuggy
huggy wuggyOP4mo ago
and I added the useJUnitPlatform()
dan1st
dan1st4mo ago
it should be src/test/java normally, not test/java - but using a different structure is possible
Crain
Crain4mo ago
/myProjectRoot
build.gradle
/src
/main/java
/test/java
/myProjectRoot
build.gradle
/src
/main/java
/test/java
This is the structure
huggy wuggy
huggy wuggyOP4mo ago
ah okay it doesn't let me choose directory option
huggy wuggy
huggy wuggyOP4mo ago
No description
Crain
Crain4mo ago
In this case package works It's mostly acting up because you defined the source location in build.gradle. /src/main is the default, so you don't need to specify it.
huggy wuggy
huggy wuggyOP4mo ago
No description
Crain
Crain4mo ago
And the build.gradle
huggy wuggy
huggy wuggyOP4mo ago
still doesn't work sadly nothing works
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?