How to use Unit tests in Laragine

In previous tutorial I teached you how to create a fully CRUD API, let’s counitue the joruney and learn how to use Laragine to test the API that we created in the previous tutorial.

Steps:

Change the value of bootstrap attribute to vendor/…


This content originally appeared on DEV Community and was authored by AbdlrahmanSaber

In previous tutorial I teached you how to create a fully CRUD API, let's counitue the joruney and learn how to use Laragine to test the API that we created in the previous tutorial.

Steps:

  1. Change the value of bootstrap attribute to vendor/yepwoo/laragine/src/autoload.php in phpunit tag (it's the same as vendor/autoload.php but with needed stuff to run the tests correctly in the generated modules and units).

  2. Add the following to Unit test suite:

<directory suffix=".php">./core/*/Tests/Feature</directory>
<directory suffix=".php">./plugins/*/Tests/Feature</directory>

  1. add the following to Feature test suite:

<directory suffix=".php">./core/*/Tests/Feature</directory>

<directory suffix=".php">./plugins/*/Tests/Feature</directory>

*Here's the full code snippet: *
image

  • Let's go to PostTest.php in core/Blog/Tests/Feature
  • There're five main functions in the file:
  • testItShouldGetListingOfTheResource() for testing get the lists of the the resource.
  • testItShouldStoreNewlyCreatedResource() for testing create a new resource in the storage.
  • testItShouldGetSpecifiedResource() for testing get a specefied the resource.
  • testItShouldUpdateSpecifiedResource() for testing update a resource in the storage
  • testItShouldRemoveSpecifiedResource() for testing remove a resource from the storage

Note

you can edit the unit tests function as you want, we just write the main methods for each CRUD.

Now open your terminal or git bash in your project and let's run the test, you can run one of the following commands:

  1. php artisan test
  2. ./vendor/bin/phpunit

image

Conclusion

I hope you found this article helpful. If you need any help please let me know in the comment section.

Let's connect on LinkedIn


This content originally appeared on DEV Community and was authored by AbdlrahmanSaber


Print Share Comment Cite Upload Translate Updates
APA

AbdlrahmanSaber | Sciencx (2021-10-04T19:04:20+00:00) How to use Unit tests in Laragine. Retrieved from https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/

MLA
" » How to use Unit tests in Laragine." AbdlrahmanSaber | Sciencx - Monday October 4, 2021, https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/
HARVARD
AbdlrahmanSaber | Sciencx Monday October 4, 2021 » How to use Unit tests in Laragine., viewed ,<https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/>
VANCOUVER
AbdlrahmanSaber | Sciencx - » How to use Unit tests in Laragine. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/
CHICAGO
" » How to use Unit tests in Laragine." AbdlrahmanSaber | Sciencx - Accessed . https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/
IEEE
" » How to use Unit tests in Laragine." AbdlrahmanSaber | Sciencx [Online]. Available: https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/. [Accessed: ]
rf:citation
» How to use Unit tests in Laragine | AbdlrahmanSaber | Sciencx | https://www.scien.cx/2021/10/04/how-to-use-unit-tests-in-laragine/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.