How to run unit tests only in a Hybris project?
Asked Answered
P

4

7

We have a large Hybris project here and to run all the tests with takes much too long (hours, yes, a large consulting company created that crap). My target is to reduce all the spring based integration tests and replace them by real unit tests.

But when running the tests with the Hybris ant build for one extension (ant alltests -Dtestclasses.extensions=myext) starts a server with the junit tenant also if there are only non Spring based unit tests in that extension. I also tried to use ant unittests but that one does not even executes my tests.

Is there any way to run only the tests annotated with @UnitTest without any server start in an ant run?

PS: I have a hybris 5.1 and 5.3 commerce suite

Pharyngology answered 11/2, 2015 at 16:13 Comment(0)
R
8

You should use ant unittests and not ant unit tests:

ant unittests -Dtestclasses.extensions=myext

Note

Running simple unit tests exclusively is not so easy whenever someone uses somewhere Registry.getApplicationContext() in the code under test!

In fact, Registry.getApplicationContext() starts a Hybris instance. If that happens to you, you need to eliminate that particular call to Registry.getApplicationContext() with a better class design and/or mocks.

Rubidium answered 11/2, 2015 at 20:58 Comment(2)
yes, Registry is the point where hybris didn't understand dependency injectionPharyngology
seems you are right for 5.3, does not work with 5.1 (no tests found)Pharyngology
L
3

This is good information. However, in my opinion, even running the unit tests for a single extension is still too much. Unit tests are supposed to be FAST! I should be able to run a single unit test method from within my IDE if I choose to. The whole concept of "red-green testing" is lost if I have to wait for a bunch of non-relevant unit tests to run every time I want to test my refactored code.

Because these tests rely on a runtime environment, there are NO unit tests in Hybris. There are only integration tests because they all rely on a running Hybris system to be executed.

Lucrece answered 1/3, 2018 at 21:37 Comment(1)
You are completely right! The whole Hybris framework is a complete mess and I never mention it as experience to be sure I never ever have to work with it. It is a real pain, worst I saw in 20 years of software engineeringPharyngology
C
0

This is for running a particular test class.

ant unittests -Dtestclasses.extensions="ext_name" -Dtest=com.erk.b2b.integrations.service.ecom.impl.ServiceImplTest

Cachinnate answered 10/4, 2023 at 17:44 Comment(0)
V
-2

I would like to give some details how to run unittests from within the IDE.

Vacuum answered 11/2, 2019 at 16:40 Comment(1)
The real point is that you just can't run unit tests without initiating at least the junit tenant in hybris which involves starting up the hybris system. In my opinion, this is a gigantic belly flop for SAP. Why can't I simply run my unit tests outside of ANY runtime? Running them from intelliJ with the hybris plugin is just another way of relying on the hybris runtime. What if I need to run my unit tests from my CI/CD pipeline? I have to either run all the tests which take over an hour, or I have to start up a hybris instance for each extension/group of tests. Sorry...this is failure.Lucrece

© 2022 - 2024 — McMap. All rights reserved.