My tests are being ignored in IntelliJ.
Hey, I'm trying ouy Java with spring boot. I have a simple guess the word game, with the word being a cocktail that is retreived with an API. User inputs their guess, and dpeending whether or not they are correct they can try again or quit. I wanted to write some tests and ran into a problem that my tests have the ignored status for whatever reason. The below code for example should test for the getcocktail method being called once for example. Tried googling but little info on the issue.
52 Replies
⌛
This post has been reserved for your question.
Hey @Luxenbau! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
Where does the "You guessed right" text etc come from?
Can you run "all tests" in some way instead of running the specific test method?
Can you try using a debugger?
It looks like you are having issues with debugging or issues that can be solved using a debugger.
Check out this article on dev.java to see how debugging works and how to use a debugger.
This Stack Overflow question and its answers also explain debugging in general.
These links describe how to use the debugger in some IDEs:
• Debugging in IntelliJ
• Debugging in Eclipse
This comes up when I run the test. This is actually the sysouts inside of the game, but they are triggered when I run the test...
Im new to UnitTesting ...
And I tried running the entire file, or all tests, its the same thing. Tests are ignored
Do you have both JUnit 4 and 5 on the classpath?
You mean in gradle?
I have for tests:
Please format your code to make it more readable. For java, it should look like this:
weird
yes I have no clue why =/
In your screenshots, there are a few icons above the test results
see the tick icon?
You mean the show only passed tests icon?
sure it's passed only?
What happens when enabling it?
The tick mark is the show passed. The crossed o is the show ignored
yes I know
nothing. if i disable the show ignored, the Test Results disappear from the left pane
ok
Can you try making the test fail in some way?
by temporarily changing some code
if you do that, does it still show as disabled?
I tried changing verify to some ridiculous number but it still gets ignored
a simple test like:
@Test
however works
This message has been formatted automatically. You can disable this using
/preferences
.so its something with the test
so other tests work as expected?
Can you try making the problematic test fail?
if i write tests that do not touch the GameService class.
I think its something with it
Did you use
@Ignore
or @Disabled
in the past?
Can you step through the test with a debugger? Does anything in it throw any exception?
the warnings should not be affecting the test at all.
maybe i mocked it somehow wrong
but it just gets ignored for whatever reason
.
those are results of the debugger? you mean the one at top right of IntelliJ?
No. That's just stdout
and stderr
It looks like you are having issues with debugging or issues that can be solved using a debugger.
Check out this article on dev.java to see how debugging works and how to use a debugger.
This Stack Overflow question and its answers also explain debugging in general.
These links describe how to use the debugger in some IDEs:
• Debugging in IntelliJ
• Debugging in Eclipse
I am talking about actually stepping through the code
hold on need to figure out how this works
so this is when i break at inputstream
can you step over the lines in your test one after the other?
Is there anything throwing an exception?
hmm, when i set breakpoint at the verify line, test is already ignored
maybe something in your code exits in some way
Are you using
System.exit()
anywhere?hmm, the exitgame method uses it yes
wait, does it exit the application and test?
that kills all tests
no way let me check this
there are maybe some ways around it but it's annoying
wow, i just temp disabled it and now it passes
i did not know the sysexit also affects the test...
tests are also just java programs
and it terminate the jvm right
kinda yes
ooohhhh, so now i need to figure out how to write tests, since my default public method calls it
thanks for the help man
The best way is not using System.exit() in your code
hmm well need to close the program somehow without throwing exceptions then. i mean its a standalone program so sysexit seems to make sense
if you can't do that, you might be able to mock System.exit
well in your application you probably have some sort of loop checking for input etc
you could also make sure that stops
yea i do have a while loop
you could also make sure that loop stops looping when you want to exit
yeah, i think so.
i insta call exit game whenever user exits or says no. i can just cancel the loop instead. wont exit the app but i can get the tests working
can instead just change the keepplaying value
most importantly i now know the issue 😄
thanks a lot man idk if i can give u rep or karma here or something @dan1st | Daniel
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@290601931611701249>.