投稿時間:2023-06-11 10:04:29 RSSフィード2023-06-11 10:00 分まとめ(4件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
python Pythonタグが付けられた新着投稿 - Qiita discode Bot開発 Permission(権限)を確認する方法 https://qiita.com/sakaki_developer/items/47ba1252335136c2152a discode 2023-06-11 09:35:21
海外TECH DEV Community Step by step to Pest PHP testing framework in Laravel 10 https://dev.to/alphaolomi/step-by-step-to-pest-php-testing-framework-in-laravel-10-6e1 Step by step to Pest PHP testing framework in Laravel IntroductionLaravel is a web application framework with expressive elegant syntax We ve already laid the foundation ーfreeing you to create without sweating the small things Automated testing is the execution of your test plan the parts of your application you want to test the order in which you want to test them and the expected responses by a script instead of a human Automated tests are able to return results quickly and are more accurate than their human counterparts PHPUnit is a testing framework for PHP It is an instance of the xUnit architecture for unit testing frameworks Pest is a testing framework with a focus on simplicity It was carefully crafted to bring the joy of testing to PHP Pest is heavily inspired by Jest You can use a variety of different testing frameworks to write tests for your Laravel applications Laravel version by default ships with PHPUnit support out of the box In addition to PHPUnit Laravel provides a variety of helpful assertions to make testing easier and faster We will use Pest testing framework in this tutorial The PestPHP testing framework offers several benefits that make it an excellent choice for testing PHP applications particularly in the context of Laravel projects Here are some of the key benefits of using PestPHP Simplicity PestPHP focuses on simplicity and aims to provide a delightful testing experience It offers an intuitive and clean syntax that is easy to read and write The framework encourages you to write tests that are expressive and straightforward reducing complexity and improving code maintainability Powerful Assertions PestPHP provides a wide range of powerful assertions including all in PHPUnit that enable you to write concise and precise tests These assertions make it easy to verify the behavior and state of your application with minimal effort With PestPHP you can express your expectations in a natural and readable manner Test Driven Development TDD Support PestPHP is designed to support Test Driven Development TDD practices It encourages developers to write tests before implementing the corresponding functionality By following a TDD approach you can ensure that your code is thoroughly tested leading to better code quality and fewer bugs Integration with Laravel PestPHP integrates seamlessly with Laravel It leverages Laravel s testing infrastructure and provides additional features and enhancements This integration allows you to test your Laravel applications efficiently taking advantage of Laravel specific functionalities such as database seeding HTTP testing and more Parallel Testing PestPHP supports parallel testing allowing you to run your tests concurrently This feature significantly reduces the overall test execution time especially for larger test suites With parallel testing you can improve the efficiency of your testing process and get faster feedback on the health of your codebase Community and Ecosystem PestPHP benefits from an active and growing community of developers The community provides support resources and plugins making it easier to adopt and leverage the framework effectively In summary PestPHP offers simplicity powerful assertions TDD support seamless Laravel integration parallel testing and a thriving community These benefits make it a compelling choice for testing PHP applications enabling you to write clean expressive tests and ensure the reliability and quality of their code To install Pest in Laravel we will use a Pest plugin for Laravel which will install Pest and it to work with Laravel Step Create new Laravel projectCreate new Laravel project using Composer or Laravel installer We will name the project pest laravel Using composer to create new Laravel projectcomposer create project laravel laravel pest laravel Or using Laravel installerEnsure you have installed Laravel installer by running this commandwill install Laravel installer globally or update to the latest versioncomposer global require laravel installerlaravel new pest laravel Step Change directory to pest laravelcd pest laravel Step InstallationPest is a developer dependency which means it should be installed using the dev flag Install Pest plugin for Laravelcomposer require pestphp pest plugin laravel dev Install Auto Configure Pest in your Laravel project will add Pest php file in your project tests directoryphp artisan pest installOptional add testing script in your composer json This will allow you to run composer test in your terminal to run your tests It is a recommended practice to add a test script to your composer json file so that other developers can run your tests by simply running the composer test command file composer json scripts test vendor bin pest Step Run testsTo run your tests you may use the test Artisan command The Artisan test runner provides a convenient wrapper around PHPUnit and Pest allowing you to run your tests using a single command php artisan testOr you may run the tests using the composer test command composer testOr you may run the tests using the vendor bin pest command vendor bin pestAll of these commands will execute the same tests By default the phpunit xml file included with your application will instruct the test runner to exclude the tests in the vendor and node modules directories Step Delete the example testsA new Laravel project comes with some example tests These tests are located in the tests directory In a new Laravel project there are two directories within the tests directory Feature and Unit Feature tests may test a larger portion of your code including how several objects interact with each other or even a full HTTP request to a JSON endpoint Unit tests on the other hand are focused solely on a single class Typically each class in your application will have a corresponding Unit test that tests that class in isolation from the rest of the application We will delete the example tests provided by Laravel default project In the tests directory delete the following files rm tests Unit ExampleTest phprm tests Feature ExampleTest php Step Create new Pest unit testsIn this step we will create a new unit test for Product model We will create a new Product model using the following command php artisan make model Product mDon t forget to add the name and price attributes to the products table migration file file database migrations create products table php public function up Schema create products function Blueprint table table gt id table gt string name table gt decimal price table gt timestamps Then run the migration using the following command php artisan migrateThen we will create a new unit test for Product model using the following command php artisan pest test ProductModelTest unitIn this Unit test we will test forProduct model has a name attributeProduct model has a price attributeCopy the following code to the ProductModelTest php filefile ProductModelTest phpit has a name attribute function product new Product name gt Product price gt expect product gt name gt toBe Product expect product gt price gt toBe Step Create Product controllerIn this step we will create a new Product controller using the following command php artisan make controller ProductController resourceThen add the following code to the ProductController php filefile ProductController php lt phpnamespace App Http Controllers use App Models Product class ProductController extends Controller public function index products Product all return response gt json products public function create product new Product name gt Product price gt product gt save return response gt json product Step Add Product routes to routes api phpfile routes api phpuse App Http Controllers ProductController Route get products ProductController class index Step Create new Pest feature testsphp artisan pest test ProductTestfile ProductTest phpit can list products function getJson products gt assertStatus it can create a product function data name gt Product price gt http created postJson products create data gt assertStatus it vs test function in PestThe it function is an alias for the test function Both functions are identical and you may use either one when writing your tests The it function is provided for developers who prefer to use the it function when writing tests Step Run testsphp artisan testOr you may run the tests using the composer test command composer testOr you may run the tests using the vendor bin pest command vendor bin pestAll of these commands will execute the same tests By default the phpunit xml file included with your application will instruct the test runner to exclude the tests in the vendor and node modules directories If you want to run a specific test you can use the filter option php artisan test filter ProductModelTestOr you may run the tests using the composer test command ConclusionIn this tutorial we explored how to set up and use the Pest testing framework in a Laravel project We discussed the benefits of using Pest a testing framework focused on simplicity and inspired by Jest By following the step by step instructions you learned how to install Pest in your Laravel project run tests using various commands and create new Pest unit and feature tests Testing your Laravel applications is crucial for ensuring their quality and reliability Pest provides an intuitive syntax and powerful assertion capabilities making the testing process more enjoyable and efficient By writing tests with Pest you can create readable and maintainable code that verifies the correctness of your Laravel application s functionality Remember to run your tests regularly to catch any bugs or issues early in the development process Testing not only helps identify problems but also provides confidence in the stability of your codebase So embrace the joy of testing with Pest in your Laravel projects and let your code be robust reliable and humorous Happy Coding 2023-06-11 00:11:24
ビジネス 東洋経済オンライン 長篠の戦いで信長を無視「家康の奇襲」成功の裏側 武田勝頼を設楽原で追い込んだ「忠臣の提案」 | なぜ天下人になれた?「人間・徳川家康」の実像 | 東洋経済オンライン https://toyokeizai.net/articles/-/677964?utm_source=rss&utm_medium=http&utm_campaign=link_back 徳川家康 2023-06-11 09:40:00
ビジネス 東洋経済オンライン 水揚げ半減!伊勢海老を脅かすウツボ激増の深刻 天敵と排除するのでなく、美味しく食するコツがある | 令和の目からウロコ | 東洋経済オンライン https://toyokeizai.net/articles/-/677856?utm_source=rss&utm_medium=http&utm_campaign=link_back 伊勢海老 2023-06-11 09:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)