Комментарии:
I'm having a very hard time trying to understanding the difference between Unit tests and Feature/Integration tests, mainly in Laravel... Why is this a Unit tests and what would be an Integration test?
ОтветитьI like the way you teach
Ответить❤️❤️❤️❤️
ОтветитьGreat video, but it is painfully TIME CONSUMING to write that much code (unit test code) for a simple if else statement. What if we needed to do this for our WHOLE source code? I understand the advantages but is it worth the disadvantage? Maybe do this selectively?
ОтветитьWow, this is so informative and elaborate. Thanks!
ОтветитьWhy are you opening folder ?
ОтветитьWhat is your suggestion for a scenario where I have to test a set of APis which have to pass through various middlewares (viz. jwt, roles and so on) and recaptcha... These APIs are supposed to call a service which eventually calls another set of external APIs (viz. google APIs) and the values returned by the external APIs are stored in the DB...
How do I go about testing that? Please advise.
Would really appreciate if you could cover this.
What about using .env.testing ?
ОтветитьThis is why you should always write your test before coding. Great work!
ОтветитьThank you very much for great tutorial video!
Ответитьthank you sir.. this is really good and helpful tutorial
ОтветитьThankyou for making it simple and clear!
ОтветитьVery nice tutorial
Ответитьis it ok to touch the database in unit tests?
Ответитьit so simple and easy to be understood. nice video.
ОтветитьWriting unit test code seems more complicated and time consuming than writing the app code itself... And how can you be sure your unit test code is valid, are you going to write test code for your test code and so on? You surely can't rely on phpunit, and you still have to test your raw code anyway. The only true way to know if your code works is to run it, in my opinion.
Ответитьwhat are benefit of using unit tests?
Ответитьsir when we have to use unit tests?
ОтветитьHelp!
I cannot access my imported classes within the tests.
I get: Error: Call to a member function connection() on null
Awesome! Very well explained, thanks!
ОтветитьWhat is difference between unit and feature tests?
Ответитьwhy everyone is using dark theme ?? I can barely see the text during the daylight
ОтветитьWhat do you think about PEST package and it's syntax? Some developers think that in future laravel versions it will be default test package
ОтветитьNice example 👍
ОтветитьIt is an integration test, not the unit. In the unit test, you should not use a database or such. You should be able to mock the data source. If you'd do it using TDD, you'd write an empty class and then tests where you would call that class and not yet existing methods, inject class with existing dependencies that would be mocked for sourcing data and create data sets that would be generated or with faked data as you said. :-)
Unit tests should not test the database which is the case in this example...
But guess its preferences. Without the database layer, unit tests would run much faster because they wouldn't need to bootstrap the whole app to test a single function or class.
If you're using facades in functions you can be assured that this function cannot be unit tested, because the whole app container handler will have to be bootstrapped.
Basically, you cannot unit test as well controller actions. So all business logic should happen before controller action. So service should be injected to let's say repository and then service should be mocked to return dummy data for testing on required method calls.
Great Work so simple and easy to be understood 🙌
ОтветитьI learned so much from your channel! Thank you! Here's hoping I ace the Laravel coding challenge for a job im applying for.
Ответитьwhat css framework did you use for this lesson?
ОтветитьIt's a nice video, but this is not unit testing. It's a feature test. It won't work without a working database, and we're not only testing the service logic, but we're also testing the Income table, and the query to find the sum amount. We could pass in the user and construct the object with the Income class injected to mock it. We could also simply delegate fetching of the Income total amount to the Controller, while using query scopes (Income::forUser($user)->fromLastYear()) since this is the application level as opposed to this service which is very much in the Domain.
Not saying this is bad or anything (it's amazing for beginners), but since I was looking for real-world examples of unit testing in Laravel, I wanted to add that comment. Cheers.
So in simple words, unit testing is important when you want to trace minor error which can not only occur due to the bad logic but also invalid data.
ОтветитьHello I'm Iranian We Can't Buy your courses(Because of sanctions) if you can have bitcoin pay in your site it will be excellent.
ОтветитьI remember doing unit tests on sqlite and dev running on mysql
Ответитьcool
ОтветитьHow are tests are performing so fast ?
On my local it takes lots of time to load phpunit and then runs test
Please help
in laravel 8 and phpunit 9.5.2 syntax factory(Model) not working. I must using Model::factory() - and its working fine.
ОтветитьIt was one of the best I have seen till now. Thanx man. Good job
ОтветитьSuperb content. Thank you!
ОтветитьNow i know why unit testing is important
ОтветитьPerfect video. Thanks.
ОтветитьWow! Thank You! That was very informative
ОтветитьHi, I have a lot of code in my controller/index, which builds me a json api from all kinds of joined tables. Is there a way to assert if all the json data is provided, that is required by the frontend, and return some error if any of these json items aren't accessible? It would be easier to test like that rather than always swap between the frontend and the backend for errors. Thank you.
ОтветитьThis was a good example... Loved it... Could you share the difference between Unit and Feature tests?? There is a lot of wrong asumptions out there.
ОтветитьHi Povilis. Do you know any "trick" to clone a database as you mention? I have a production database and I want to start testing with a clean database as you mention in the video! (I have no migrations as is a legacy project)
ОтветитьThanks for the video. Waiting for more videos in this and services.
Ответитьwhy not artisan test
ОтветитьI usually go with the repository pattern, injecting a repository interface into the service and at the Unit test I use a mock of that to get data from the "database". According to Uncle Bob a Unit Test should be able to work either you have a database or not having one. Also by randomly generating data you can not be sure in every test what the outcome will be. Maybe works in this case but if you wanted to check the total amount of a period it would not work unless you insert specific data to test. Anyway, I really like your videos, there are very helpful.
ОтветитьThis is what I'm looking for, hoping to see more of these. Thanks, Laravel Daily for sharing your daily knowledge. Godbless.
Ответить