Questions tagged [unit-tests]
Denotes questions related to unit testing on Magento.
13
questions
52
votes
3answers
8k views
Run tests for a specific module in Magento2
Running the tests for Magento to using php bin/magento dev:tests:run takes a lot of time.
Is there a way to run the tests for a specific module only?
I'm a noob in (unit) testing so have mercy.
9
votes
2answers
2k views
Magento 2 : When to use Object Manager in Unit tests?
So I recently stumbled upon a problem while writing a unit test in Magento 2. You can read more about the problem in question here.
Vinai told me it is generally bad practice to use the object ...
4
votes
3answers
1k views
Fatal error: Class 'Codeception\Platform\Extension' not found. Issue occurred after magento 2.3.0 upgrade to 2.3.1
Preconditions (*)
1.Magento 2.3.1 upgraded from Magento 2.3.0
Php 7.2.15
OS : Ubuntu 18.04 Bionic
Phpstorm 2019.1.1
Evnironemnt : Magento development
Steps to reproduce (*)
Issue appears after ...
5
votes
1answer
2k views
How to obtain the Object Manager in Unit-Tests?
I've created the second unit-test for my second class. The second class will take a dependency of a first class instance and in one test I'd like to use the object manager to create the second class.
...
9
votes
3answers
2k views
Generate factory or proxy in unit tests: “ReflectionException: Class …Factory does not exist”
As far as I understand, Factory and Proxy classes are generated on the fly by the autoloader if they do not exist yet in var/generation (see: What Triggers the Generation of a Factory in Magento 2)
...
8
votes
2answers
2k views
How to mock a Context object
I am trying to test a module which contains a context object as follows:
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Catalog\Model\Product\...
3
votes
1answer
2k views
Magento 2 : Unit test with mock data don't work. Why?
I'm trying to write unit tests for my code, but for some reason I can't get it to work. To simplify it, I have the following:
namespace Custom\Shipping\Model\Config\Source;
use Custom\Foundation\...
2
votes
2answers
3k views
How run unittest using EcomDev_PHPUnit module?
Here is described old version: http://www.ecomdev.org/2011/02/01/phpunit-and-magento-yes-you-can.html
And they wrote that I need call phpunit UnitTests.php
But I have magento v.1.7. I downloaded ...
4
votes
2answers
419 views
How to get base url in Unit Test?
This is my unit test in my custom module:
namespace Star\Trek\Test\Unit\Model;
class BeyondTest extends \PHPUnit\Framework\TestCase
{
}
How can I get my Magento 2 base URL in there?
3
votes
1answer
808 views
Simulating Order Data For a Unit Test
I am currently writing my first unit test. The basis of the test is I get all of the order information along with the items and create a JSON object from it. Is there a way to create dummy items and ...
2
votes
1answer
217 views
EcomDev PHPUnit Translation not Working with Mocked Helper
I noticed that translations are not working with the EcomDev_PHPUnit Unit Test framework if you replace a helper with a mocked helper, using mockHelper() and replaceByMock(). Shouldn't any call to the ...
1
vote
1answer
410 views
How to mock an external resource in Magento 2?
I want to write unit test for a module which contains these functions:
public function abc($Str)
{
$n = $this->def();
...
return x;
}
public function def()
{
...
$productRepo=...
0
votes
1answer
459 views
How to write a test for custom router and plugin in magento 2?
I have created a module in magento 2 for adding prefix to the url of all product and category.
here is the snippet code for the router :
/**
* Match route pages for handling cp / ip
*
...