Questions tagged [unit-tests]
Denotes questions related to unit testing on Magento.
117
questions
1
vote
0answers
57 views
Magento 2 Unit Testing with Helper dependency
I have a Helper class and a Model class, which looks like
<?php
# File: app/code/MagePsycho/Catalog/Helper/Data.php
namespace MagePsycho\Catalog\Helper;
use Magento\Framework\App\Helper\...
0
votes
0answers
6 views
Difference in output between Model method and Test/Unit method for Model?
I have created one more custom attribute (custom_image_type) based on frontend_input = media_image.
I just ran the following File level unit test on below file.
\Magento\CatalogImportExport\Test\Unit\...
1
vote
1answer
28 views
How the unit tests in magento 2 are useful?
I'd like to know, what are the core benefits of running tests in
magento ?
How & what can be determined from the tests ?
How to run a test ?
1
vote
0answers
17 views
Unit test 'non-existent' factory methods
Potentially same question has been asked but differently.
You are testing something in isolation and assume no access to generated folder.
Helper method
class HelperClass extends AbstractHelper
...
0
votes
0answers
8 views
Magento 2 How to run a functional-test
In the following list
https://devdocs.magento.com/guides/v2.4/reference/mftf/functional-tests.html
i want to run this test
UnassignProductsFromCategoryBySKUsTest
[Visual Merchandiser] Admin should be ...
1
vote
1answer
278 views
Magento 2 API testing
I have created an API and I want to write test files for that API. How can it be done in Magento 2.3.5? I have referred the link - https://devdocs.magento.com/guides/v2.4/get-started/web-api-...
2
votes
1answer
628 views
createMock vs createPartialMock vs createConfiguredMock (PHP unit methods in Magento 2)
What is the difference between createMock, createPartialMock and createConfiguredMock methods of PHPUnit\Framework\TestCase class in Magento 2?
0
votes
0answers
8 views
php unit interface not working
So i have my interface in di.xml
<preference for="Module\Example\Widget\List\StrategyManagerInterface" type="Module\Example\Widget\List\StrategyManager" />
<type name="Module\Example\Widget\...
0
votes
0answers
9 views
Unit test array asserting error
I try to pass array http://joxi.ru/MAjan8dUxgEz62, and as result i get error message http://joxi.ru/8Ann1gaC7Qw14A
1
vote
0answers
547 views
Executing Jasmine tests for frontend theme's
I can't get some of the Jasmine tests for the frontend (blank and luma themes) to work.
I have generated the static files as described in the documentation.
$ bin/magento setup:static-content:deploy ...
0
votes
1answer
76 views
Magento2.3 : Unit Case writing for Observers
I was wondering what is best practice for Unit test case writing for observers ?
I looked for examples in core , and found below file
magento/module-sales/Test/Unit/Observer/...
1
vote
0answers
329 views
Code Coverage with Jasmine Unittests in Magento2
I am trying to set up the jasmine Unittests for Magento 2. I've already edited the settings.json inside the dev/tests/js/jasmine/spec_runner directory, to only test my own unit tests because I don't ...
4
votes
2answers
388 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?
4
votes
1answer
363 views
Class 'Magento\TestFramework\TestCase\AbstractController' not found when running unit test for custom module
I tried to make a unit test for my custom module like this:
app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php
namespace MyCompany\UnitTest\Controller;
class SpinTest extends \Magento\...
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 ...
1
vote
2answers
702 views
Magento 2 magic methods phpunit tests
I've started learning and at the same time writing tests for my Magento 2 custom development. Not a ride in the park. It feels like digging a pit in the sand sometimes. I got to the point where I need ...
1
vote
1answer
827 views
Trying to mock Store getLocale, getting “Method cannot be configured…”
I have this Magento 2 unit test code:
$storeInterfaceMockDe = $this->getMockBuilder(\Magento\Store\Model\Store::class)
->disableOriginalConstructor()
->setMethods(['...
0
votes
1answer
955 views
Magento 2.3: Write unit test for Observer
I am writing a unit test for an observer invoking sales_order_place_after event.
SendOrderToVenuePay Observer
class SendOrderToVenuePay implements \Magento\Framework\Event\ObserverInterface
{
...
0
votes
1answer
112 views
@magentoDbIsolation triggers fatal errors
When running integration tests for my custom Magento module, usage of the annotation @magentoDbIsolation causes this error to be logged:
PHP Fatal error: Uncaught Doctrine\Common\Annotations\...
0
votes
1answer
165 views
What is the use of Test/Unit folder in module ? What is the purpose?
In magento 2, I see in so many modules that there are Test/Unit folder available. I know little bit about that it used for unit test purpose.
But, I want to know that :
What is the purpose of this ...
0
votes
1answer
55 views
How to catch exeption in unit test and check it
I have a model class, that throw exception if some value is null.
How I can test, that it condition is ok.
$contact = $this->contactFactory->create()
->setEmail('testdelete@...
2
votes
0answers
112 views
How to post form data from Unit Test controller to custom controller | Magento 2
I have a custom module with form. I want to post values from unit test file to my custom module controller.
I tried
$this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::...
-1
votes
2answers
350 views
How to Write test-cases for more than one function in magento 2?
In my .php file I have more than one function , how I can write test cases for that?
2
votes
0answers
119 views
What is the correct way to create Mock input interface in Web-Api functional test?
I've already write successfully a Web-Api unit test for a Custom API. But I'm wondering if there is a way to automatically create a Mock for input data for the API?
For example, AccountManagement ...
3
votes
0answers
143 views
Cart observer unit testing
I created a module that has some logic to modify the price of certain items depending on a few conditions pertaining to the other items in the cart.
I'm trying to write a unit test to test that the ...
4
votes
0answers
231 views
Unit testing ina Magento 2 - Mocks and Assertions
Open file
\Magento\Cms\Test\Unit\Model\PageRepositoryTest
and take a look at the setUp() method
/**
* Initialize repository
*/
protected function setUp()
{
$this->pageResource = $this->...
2
votes
0answers
84 views
Unit Testing With Magento 2
Where should i start working with extension development using test driven approach, with Magento 2. I do not see any resources and tutorials from where I get idea. I believe I have a fair amount of ...
14
votes
1answer
163 views
Magento2 Chrome Driver Service error in MTF
I am new to MTF. I have followed the magento2 tutorial based on the following link
But When I am running the command
vendor/bin/phpunit
I am getting the following error -
Fatal error: Uncaught
...
1
vote
1answer
46 views
Magento2 Object Manager Issue in MTF test run windows
I am learning on how to use MTF in my test module. I am trying to run generator using command
php generate.php
But I am getting following error -
Uncaught Error: Class 'Magento\Mtf\...
1
vote
0answers
144 views
Magento 2 : How can I test save and delete model?
I have the problem with writing unit tests. It's my first attempt and I don't know how can I test a couple of cases in my code.
It's action in my controller:
public function execute()
{
...
2
votes
0answers
96 views
Magento2 Unit Testing
I'm trying to understand the Unit Testing for Magento2.
public function getPostUrl()
{
$ticketId = $this->getRequest()->getParam('ticket_id');
$params = ['ticket_id' => $ticketId];
...
4
votes
1answer
881 views
How to use collection factory model in Unit Test magento 2
I have a custom extension with model with structure like this in database:
+----------------------------------+
|entity_id | customer_id | balance |
+----------------------------------+
| 1 | ...
1
vote
2answers
652 views
How to create mock for factory classes?
In unit testing I want to create mock object for factory classes e.g.
$this->getMockBuilder(\Magento\Framework\Controller\Result\RawFactory::class)->disableOriginalConstructor()->getMock();
but I ...
0
votes
0answers
542 views
Unit test in magento 2 Error: Call to a member function getAllVisibleItems() on null
Am finding difficult to unit test my custom functions. Below is my custom module's model function which i used for fetching cart informations.
<?php
namespace Namespace\MiniCart\Model;
use ...
4
votes
1answer
173 views
Magento1 - tests - phpunit compatibility
I am currently working on a project (magento 1.9) where tests are developed using PHPUnit 4.8, ECOMDev and TechDivision/magento unit testing (https://packagist.org/packages/techdivision/...
2
votes
3answers
3k views
Magento2 unit tests doesn't run using vendor/bin/phpunit or vendor/phpunit/phpunit/phpunit
Env:
PHP 7.0.27-1+ubuntu16.04.1+Clear Magento 2.2.2 with sample data (downloaded in archive)
I have created new test module that very simple with unit test for one class.
When I run
php bin/magento ...
1
vote
1answer
935 views
Magento 2 Unit Test error: Call to a member function getBaseUrl() on null
I am looking to write basic unit tests for some helper functions that I am working on for a Magento 2 module. I am able to execute my custom module unit tests but I am getting the following error for ...
2
votes
1answer
593 views
What is Magento Functional Testing Framework (MTFT)
With the new release of Magento version 2.2.2 in release notes they have mentioned a new feature as Magento Functional Testing Framework (MTFT). What is this framework do exactly?
Is this a option/...
1
vote
1answer
125 views
unit test with phpunit
I create simple unit test with object manager with class name
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)
and object Name ModuleList like
$...
3
votes
0answers
276 views
How to write Unit test for my blocks in magento 2
I have created a module and its working fine.
I want to write Unit test for it(i know that i should write unit test before writing code).
I tried this way , but i am not clear about it.
My Block ...
6
votes
2answers
284 views
What we can achieve by unit test in Magento 2 ? How it is useful?
I don't know how can we do unit test of our module in Magento 2?
What will be benefits of doing a unit test on our Magento 2 module?
what will be the outcome of the unit test in Magento 2?
Which ...
1
vote
2answers
861 views
Magento 2 Unit test for exception
Got a basic question about handling Exceptions in Magento 2. I'm currently on Magento 2.2 with PHPUnit 6.2.4. I would like to write a test for a CouldNotSaveException.
Got the following code example
...
0
votes
1answer
31 views
Magento 2 TEST_SUITE=functional ACCEPTANCE_INDEX=1
Pull request errored with message:
"The job exceeded the maximum time limit for jobs, and has been terminated."
ref: https://travis-ci.org/magento/magento2/jobs/285215690
Never used before.! what ...
6
votes
1answer
664 views
Unit test Issue on getting value
I am creating a unit test for my simple method, this method get the value from requestHeader
here is my class which I want to create test class
namespace Vendor\Module\Helper;
use Magento\Framework\...
3
votes
1answer
4k views
What is the correct way to create mock object in unit test
Now days I am focusing on TDD development, and I am following the Magento test class for reference. So firstly I look into Contact module (as it is the small module) and I found that in DataTest.php ...
0
votes
1answer
438 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
*
...
2
votes
1answer
69 views
Magento\Mtf\TestCase\Scenario Location file?
I was installing some module and found that there are some test class that extend Scenario :
<?php
namespace Aheadworks\SocialLogin\Test\TestCase;
use Magento\Mtf\TestCase\Scenario;
/**
* ...
0
votes
1answer
169 views
Magento 2 Travis Unit tests errors
I've set up Travis with Magento 2 unit tests to test our code. My PHPunit config is like this:
File dev/tests/unit/phpunit.custom.xml.dis:
<testsuite name="Magento Unit Tests">
<...
1
vote
1answer
745 views
Unit test case for custom module REST API
I wanted to write unit test case for custom REST API in magento2.
I have already gone through the : http://devdocs.magento.com/guides/v2.0/get-started/web-api-functional-testing.html
I am getting ...
3
votes
1answer
439 views
Magento2 - Why would Magento Test Framework - Integration tests fail on a clean composer install
Firstly as I'm using Magento Enterprise I don't think I can pull against a git repository where I know the tests are passing. I presume that these are being run in travis-ci.com rather than .org
...