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

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