JUnit succeeds when run as "debug as junit test" but fails as "debug as gradle test".
I'm doing a simple hibernate test and the code all works fine when run from Eclipse normally as well as when I create a junit to test it.
But I'm now trying to run as ./gradlew test (from bash or within eclipse) and I'm having a problem with:
em.persist(jazz);
causing:
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.IllegalArgumentException: Unable to locate persister: entities.Genre
There must be some config or context which is missing from the gradle test which is generally present.
18 Replies
⌛
This post has been reserved for your question.
Hey @Dave12345! 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 marked as dormant after 300 minutes of inactivity.
I assume you imported it into Eclipse as a Gradle project?
Are there any other logs?
It was created as a gradle project. I can clean/build just fine. I can run it on the command line by copying the command line params from eclipse.
What logs should I be looking for? I've added log4j logging which is how I know about this error.
What logs should I be looking for? I've added log4j logging which is how I know about this error.
the full output of
./gradlew test
there's nothing very exciting there.
https://scans.gradle.com/s/cdu536ugrm2om/console-log?anchor=28&page=1
Can you attach a debugger?
Not sure. I mean, I can try anything you suggest! I can run the test from within eclipse if that's easier.
Well as long as you can debug it in Eclipse and use breakpoints but still run the test in a way that fails
org.hibernate.internal.SessionImpl.firePersist(PersistEvent)
L760:
fastSessionServices.eventListenerGroup_PERSIST
.fireEventOnEachListener( event, PersistEventListener::onPersist );
MappingException
I mean, I'm guessing, though, that this is an example of a wider problem, right? If any code works in junit but not via gradlew then I'm missing some setup/config code, right?
I think tests can see stuff in main/resources so it's not that
probably
Is there any file that's in both main/resources and test/resources
like the same filename/path
Can you show a screenshot of the project structure?
typically there's something with your setup but there are a few things Eclipse does differently
there is nothing at all in test/resources
(I tried copying stuff there earlier but it made no diff)
ok
Does the issue also happen locally or is it a CI thing?
What files do you have in your resources?
Can you show your persistence.xml?
there's no CI here - just me experimenting with stuff on my laptop.
from the junit class, which has two tests, i can debug as junit and both tests pass. one test literally is just assertequals(1,1) to check I was running tests properly from gradle.
Running just that tests (with the other commented out) I can run it via junit and gradle (gradle both from within eclipse and from the command line).
Persistance.xml:
my config is in hibernate.properties
but that's just db setup
Are you using plain hibernate?
What's the package for the entities? Where are your tests?
💤
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.
Yes, this is my first hibernate project - I have 3 classes each with a couple of fields.
tests are in src/test/java
entities are in src/main/java
which packages?
everything is in the package "hibernate"
just diffing a log from both environments (junit and gradle).
noticed:
PU root URL: file:/home/anon/dev/projects/hibernate/lib/build/resources/test/
vs:
PU root URL: file:/home/anon/dev/projects/hibernate/lib/bin/main/
for gradle/junit