arquillian-core icon indicating copy to clipboard operation
arquillian-core copied to clipboard

[ARQ-2231] The JUnit 5 container does not work with manual mode tests

Open petrberan opened this issue 1 year ago • 4 comments

Resolves #543

Opening this as a draft to discuss the solution as it seems a little hack-y to me @starksm64

https://issues.redhat.com/browse/ARQ-2231 and https://github.com/arquillian/arquillian-core/issues/543

The problem there is that Arquillian goes through several phases, each creating and removing contexts (as to why I have no idea, haven't found any docs). The error comes at the moment the BeforeEach method tries to deploy the deployment but is unable to find out just because the proper context has already been deactivated. I can't even activate the context without finding the correct deployment, which I cannot do since the context is deactivated.

In the end, the only solution I was able to find was to not deactivate the context just before the deployment and leave the deactivation for After class. I'm not sure if that would be a problem at all, but all other solutions failed - even closing the context after obtaining the deployment to deploy, seems like by that time the context is needed again and is not activated again.

For that reason I had to introduce the arquillian-junit5-core dependency, that is the closest it can get to the actual deployment without breaking anything

petrberan avatar Mar 19 '24 21:03 petrberan

I don't think we can really have a dependency on arquillian-junit5-core here. That could potentially break JUnit 4 and/or TestNG support. However, I feel this gives a place to look.

There is a chance, though we'd need to test, that we do need the context activated for an undeploy in the @AfterEach or @AfterAll.

One thing I wonder is if we simply just need to activate contexts in JUnit when before/after are invoke. I'm not sure how we do that though.

jamezp avatar Mar 20 '24 14:03 jamezp

Thank you @jamezp . That is true, said dependency made JUnit 4 tests unusable. For that, I replace it with the closest context available, which is Before, but that fails some tests. In the current commit it's commented out

New solution is a single case workaround. There's a new check in the deployment method, which checks if the classContext is active or not. If not, that means only one thing - the deployment is managed and deploy is invoked from BeforeEach method. In such a case, it looks up in the stacktrace to find out which class called the deploy and activates the context to find the deployment.

Deactivating might be needed after the deployment is found, I'll look into that tomorrow. As always, every input is very much welcomed

petrberan avatar Mar 20 '24 20:03 petrberan

PR is now ready to merge, the changes has been tested with WFLY -DallTests and Resteasy and none of the builds broke, so I'd assume it's safe to merge

petrberan avatar Mar 22 '24 15:03 petrberan

The solution has been reworked, WFLY passes

petrberan avatar Mar 25 '24 18:03 petrberan

Anyway, here's the changes I had locally when I was toying with this and that do fix the problems: https://github.com/arquillian/arquillian-core/pull/546

rhusar avatar Apr 03 '24 13:04 rhusar

This makes sense to me and seems to be working. Thank you @petrberan!

Perhaps have a look at https://github.com/arquillian/arquillian-core/pull/546

I'm not sure if we need to do the same thing for the interceptBeforeAllMethod and interceptAfterAllMethod methods, but it feels like we should.

I have the same feeling but that couldn't find the reason why it would be necessary.

rhusar avatar Apr 03 '24 13:04 rhusar

I'll check tomorrow if the interceptBeforeAll and AfterAll are needed

petrberan avatar Apr 03 '24 14:04 petrberan

That's a good point about invoking before() and after() twice. It likely does make sense to go with something more like #546. When I run the reproducer with those commits, I do see before() only invoked once.

jamezp avatar Apr 03 '24 16:04 jamezp

Closing this in favor of #546

starksm64 avatar Jun 28 '24 16:06 starksm64