4

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 orders with preset data?

1
  • You're looking for "fixtures"
    – scrowler
    May 24, 2016 at 0:10

1 Answer 1

8

You should distinguish between unit and integration tests.

Unit Test

In a unit test the class under test should get the order data from a collaborator that you can inject as a mock, for example the OrderRepositoryInterface.

Integration Test

If you want to get test order data from the database, consider writing an integration test instead of a unit test.

Then use the @magentoDataFixture Magento/Sales/_files/order.php annotation to create a test order fixture for the test.

1
  • Here you will find some more information about test fixtures
    – naitsirch
    Jan 23 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.