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

42 messages · Page 1 of 1 (latest)

placid grove
ancient canopyBOT
#

This post has been reserved for your question.

Hey @placid grove! 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.

brisk wind
#

Can you show your dependencies?

#

How are you running the tests?

placid grove
#

okay wait

short venture
#
sourceSets {
  test {
      java {
        srcDirs = 'src'
      }
    }
}

@placid grove

placid grove
#

still not working

short venture
#

In that case we'll swap to the more traditional approach, let me knab a screenshot

#

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.

placid grove
#

yeah but when I add module test it creates another main

#

in the src

short venture
#

You aren't creating another module

#

Just a directory

placid grove
#

so I have to create a directory test in the src

#

and is java a directory or package

short venture
#

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()
}

In your build.gradle

placid grove
#

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

#

and I added

#

the useJUnitPlatform()

brisk wind
#

it should be src/test/java normally, not test/java - but using a different structure is possible

short venture
#
/myProjectRoot
build.gradle
/src
  /main/java
  /test/java
#

This is the structure

placid grove
#

ah okay

#

it doesn't let me choose directory option

short venture
#

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.

placid grove
short venture
#

And the build.gradle

placid grove
#

still doesn't work

placid grove
#

sadly nothing works