Documentation / Ressources for Testing


#1

Hi,

I found a general view about testing concepts in the documentation but nothing concrete what to do if i want to write my own tests.

Is there any kind of documentation about it?

With

console code:test

it seems, only core functions will be tested because the -m option says

"Name of core module to run tests for "

with

codecept:test

it seems that its pretty the same like code:test … this will stop somewhere with an PDO connection exception

SQLSTATE[08006] [7] FATAL: remaining connection slots are reserved for non-replication superuser connections

It seems, there are too many connections open. However, i dont want to test the core code, i want to test my own code.

How to achieve this?

Sorry, i have no experience with codecept

Best regards


#2

Hey Jim,

to test your own code, you need to create codeception.yml in your project folder. see a module that does this:


see how they split source code (src directory ) and tests (tests directory)
and this is a module/package so not really CORE

in codeception.yml (it is in repository root directory) you define everything about them. If you don’t know how codeception works, there’s a doc on their page:
https://codeception.com/docs/01-Introduction


#3

Hi @janmyszkier

there is already a configured codeception.yml by default in the spryker b2c demoshop (https://github.com/spryker-shop/b2c-demo-shop/blob/master/codeception.yml). And yes, there are also tests for Pyz in the tests folder which are indeed on project level. But i don’t want to run all this existing tests since there are errors with too many database connections during the tests.
Thats why i wanted to test just only my module.

So i expect to use the -m option

console code:test -m MyTestModule

But the hint in the command says

-m, --module[=MODULE] Name of core module to run tests for (or “all”)

So the command fails with

ErrorException - Exception: This bundle does not exist

My testmodule isn’t a core module but there is no other option provided for testing my module on the project level.

How can i explicit test my module without running already prepared tests under PyzTest ?


#4

well, to be honest, it should NORMALLY work by providing the -c parameter, so:
vendor/bin/codecept run -c vendor/spryker-eco/adyen (if you’re currently in project root dir)
where with -c parameter you provide path to your codeception.yml directory.

However, due to some unknow reason there’s that hackish solution here again I keep seeing at spryker which requires you to run off the virtual machine spryker provides and the project needs to be directly in a directory called “current”:

so you should be able to run this off within virtual machine only until Spryker decides to finally support non-VM shop instances in their code.

Then again, I’m not spryker core team member, so maybe there’s a way to configure it.


#5

I am confused … in your example there is a test folder in the corresponding package … transfered to my situation this should be the project folder. But in the demo shop there is already a test folder and a codeception.yml in the project folder. And there are already tests in it, i don’t want to execute, because the tests will not work for some reason (i don’t want to know in detail).
I just want to test my self created tests …


#6
PyzTest\Zed\Calculation.Business Tests (7) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
E CalculationWithCalculableObjectFacadeTest: Calculator stack with gross price mode 
E CalculationWithCalculableObjectFacadeTest: Calculator stack with gross price mode (0.39s)

In ConnectionFactory.php line 43:
                             
  Unable to open connection  
                             

In PdoAdapter.php line 72:
                                 
  Unable to open PDO connection  
                                 

In PdoConnection.php line 59:
                                                                                                                 
  SQLSTATE[08006] [7] FATAL:  remaining connection slots are reserved for non-replication superuser connections

#7

@JimPanse, please make sure your test configs have correct data set in them, see this one as an example:


you’ll have to adjust your “test” configs too to match your environment setup.