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

No description
26 Replies
JavaBot
JavaBot2w 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
dan1st2w ago
Can you show your dependencies? How are you running the tests?
Allan
AllanOP2w ago
okay wait
Allan
AllanOP2w ago
No description
Allan
AllanOP2w ago
No description
Allan
AllanOP2w ago
No description
Crain
Crain2w ago
sourceSets {
test {
java {
srcDirs = 'src'
}
}
}
sourceSets {
test {
java {
srcDirs = 'src'
}
}
}
@Allan
Allan
AllanOP2w ago
still not working
Crain
Crain2w ago
In that case we'll swap to the more traditional approach, let me knab a screenshot
Crain
Crain2w 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
Allan
AllanOP2w ago
yeah but when I add module test it creates another main in the src
Crain
Crain2w ago
You aren't creating another module Just a directory
Allan
AllanOP2w ago
so I have to create a directory test in the src and is java a directory or package
Crain
Crain2w 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
Allan
AllanOP2w 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
Allan
AllanOP2w ago
No description
Allan
AllanOP2w ago
and I added the useJUnitPlatform()
dan1st
dan1st2w ago
it should be src/test/java normally, not test/java - but using a different structure is possible
Crain
Crain2w ago
/myProjectRoot
build.gradle
/src
/main/java
/test/java
/myProjectRoot
build.gradle
/src
/main/java
/test/java
This is the structure
Allan
AllanOP2w ago
ah okay it doesn't let me choose directory option
Allan
AllanOP2w ago
No description
Crain
Crain2w 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.
Allan
AllanOP2w ago
No description
Crain
Crain2w ago
And the build.gradle
Allan
AllanOP2w ago
still doesn't work sadly nothing works
JavaBot
JavaBot2w 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.
Want results from more Discord servers?
Add your server