Skip to main content

Magento 2 set up integration tests.

links: 

https://devdocs.magento.com/guides/v2.3/test/integration/integration_test_execution.html

0. Install Magento and netsuite-m2 module.

1. Set up the integration test framework.

1.1 Create an integration test database all tests will run there

CREATE DATABASE magento_integration_tests;
GRANT ALL ON magento_integration_tests.* TO 'magento2_test_user'@'localhost' IDENTIFIED BY 'db-password';

1.2 Configure the framework for test environment

Create mysql config. 

cd dev/tests/integration/

mv etc/install-config-mysql.php.dist etc/install-config-mysql.php

Set up correct test database access credentials in file  install-config-mysql.php

<?php

return [
    'db-host' => 'localhost',
    'db-user' => 'magento2_test_user',
    'db-password' => 'db-password',
    'db-name' => 'magento_integration_tests',
    'db-prefix' => '',
    'backend-frontname' => 'backend',
    'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
    'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
    'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL,
    'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME,
    'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME,
    'amqp-host' => 'localhost',
    'amqp-port' => '5672',
    'amqp-user' => 'guest',
    'amqp-password' => 'guest',
];

 Adjust the PHPUnit configuration file

cd dev/tests/integration/

mv phpunit.xml.dist phpunit.xml

TESTS_CLEANUP constant in the phpunit.xml

If this constant is set to enabled, the integration test framework cleans the test database and reinstalls Magento on every test run. This way, any new modules will be automatically picked up and any artifacts left behind by previous test runs will be removed. It also causes the test framework to flush the test Magento configuration, the cache , and the code generation before executing any tests.

<const name="TESTS_CLEANUP" value="enabled"/>

To force the test framework to regenerate the cache and the other files, remove the directory:

rm -r dev/tests/integration/tmp/sandbox-*


2. Set up and run module integration tests.
2.1. Add a test suite configuration for NetSuite module, like the following, to the <testsuites> section of the phpunit.xml file so they are included during test execution.

<testsuite name="NetSuite">
    <directory>../../../app/code/RocketWeb/NetSuite/Test/Integration</directory>
    <exclude>../../../app/code/Magento</exclude>
    <exclude>../../../vendor/magento</exclude>
</testsuite>

other cases for test suite. 

<!-- Few files for test -->
<testsuite name="NetSuite">
	<file>../../../app/code/RocketWeb/NetSuite/Test/Integration/Model/Process/Import/ReturnauthorizationTest.php</file>
	<file>../../../app/code/RocketWeb/NetSuite/Test/Integration/NCTests/CustomerTest.php</file>
	<file>../../../app/code/RocketWeb/NetSuite/Test/Integration/NCTests/ProductTest.php</file>
    <exclude>../../../app/code/Magento</exclude>
    <exclude>../../../vendor/magento</exclude>
</testsuite>
<!-- Dir for test-->
<testsuite name="NetSuite">
	<directory>../../../app/code/RocketWeb/NetSuite/Test/Integration/NCTests</directory>
    <exclude>../../../app/code/Magento</exclude>
    <exclude>../../../vendor/magento</exclude>
</testsuite>


2.2 Run integration test.

cd dev/tests/integration/
php ../../../vendor/bin/phpunit --testsuite "NetSuite"
or 
php ../../../vendor/bin/phpunit --testsuite "NetSuite" --debug

3. Known Issues with NS real tests. 

If you are getting errors during running next tests:

Model/TestNetSuiteFixturesTest.php
NCTests/CustomerTest.php
NCTests/ProductTest.php
NCTests/SalesTest.php

You should be sure that all records after preview test runs have been deleted. 
https://tstdrv1050922.app.netsuite.com/app/common/entity/custjoblist.nl?searchtype=Customer - should not contain records with "name" = "customer-general@rocketweb.com_1"
https://tstdrv1050922.app.netsuite.com/app/accounting/transactions/transactionlist.nl?searchtype=Transaction - should not contain records with "account" = "1000 Checking"
https://tstdrv1050922.app.netsuite.com/app/common/item/itemlist.nl?searchtype=Item 
https://tstdrv1050922.app.netsuite.com/app/accounting/transactions/transactionlist.nl?Transaction_TYPE=InvAdjst -  should not contain records with "name" like "configurable-simple-sku-test3" or "configurable-sku-test" etc. 

Also you you can check the log requests sent to NS server
https://tstdrv1050922.app.netsuite.com/app/webservices/syncstatus.nl