Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run unit tests only in a Hybris project?

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

like image 796
Arne Burmeister Avatar asked Feb 11 '15 16:02

Arne Burmeister


People also ask

Which is an optional framework for testing your code with unit and integration test in hybris?

Use Mockito, which comes with Hybris, for your unit tests.

How do I keep the junit tenant running?

Go to Platform > Tenants. Go to the junit Tenant. Click on the button Activate.


2 Answers

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.

like image 85
ksokol Avatar answered Oct 04 '22 07:10

ksokol


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.

like image 42
jkilgrow Avatar answered Oct 04 '22 06:10

jkilgrow