-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My TicketBeast notes #97
Comments
👍
…On Mon, May 6, 2019 at 7:58 AM Duilio Palacios ***@***.***> wrote:
I'm rewatching this course and thought about sharing some of the notes I
wrote in my notebook while watching it for the first time. Is this useful
to anybody? If so please thumbs up (or thumbs down if it's not). I'm
thinking about adding the rest in this same thread as I go through the
course again.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#97 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD26OZN2X6ZM7PBJEUWEMTTPT7QJJANCNFSM4HK54F5A>
.
|
Please, do not comment a thumb up, but add a reaction on @sileence comment instead. |
Agree with that. It’s kinda annoying.
Mit freundlichen Grüßen,
Florian Wartner
Am 6. Mai 2019, 13:06 +0200 schrieb Clément Baconnier <[email protected]>:
… Please, do not comment a thumb up, but add a reaction on @sileence comment instead.
Subscribers like me don't want to get notified every time
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sorry about that guys, I deleted my comment and since there's enough interest and activity here I will just continue editing the main text to add the rest of the notes as I go through the course! |
Adding my notes onto this :) Steps for creating functionality are:(notes/details for steps are located below the steps)
Details for above steps
Notes to self:
WIP and I would appreciate any constructive criticism. :) More useful resources/notesAdam Wathan - Chasing "Perfect" (removing conditions and improving clarity) Pt. 2 of above Refactoring with Collections & Null Objects (spiritual part 3) Livewire Eloquent subqueries Adam Wathan API Drift |
Get the ball rolling
Focus on the value you want to deliver with your application.
Work backwards ⬇️
Choose most important thing your app needs to do?
Then start with the most simple test (of the most important feature):
Test structure
Tests are usually divided into 3 parts:
Arrange: Setup the conditions necessary to perform the test (A.K.A. given). i.e.: Create a concert.
Act: Run the code you want to test (A.K.A. when). i.e.: Purchase concert tickets
Assert: Make assertions to verify outcome (A.K.A. then) i.e.: Make sure the customer was charged the correct amount and that an order exists for that customer.
Direct model access
Your test code has direct access to the domain code in your app. This allows you to:
Programming by wishful thinking
Write the code you wished it existed and then use the failing tests to implement that code.
Model Factories
Factories allow us to keep our tests focused on the things that are actually important.
Other Tips
💡Store money as cents (instead of float points).
⚠️ Think harder, don't hope tests will give you all the info you need! (or detect all possible errors).
💡Look for opportunities to make your tests faster (i.e. by not migrating or talking to the database).
💡See a test failing for a reason you'd expect it to fail is a good way to know you've got your test right.
Purchasing Concert Tickets
Browser Testing vs Endpoint Testing
Browser testing: simulate the user's actions inside the browser.
✅ Simulate how a user would interact with the application.
⚠️ Slower
⚠️ Brittle
✅ Gives complete confidence the app is working end-to-end.
Endpoint testing: simulates how the browser would interact with the server (instead of how the user would interact with our app), by making HTTP requests directly to an endpoint.
✅ Faster
⚠️ Untested gap between frontend and backend
✅ Interact with more stable data structures (won't break if aesthetic changes are made to the UI)
✅ Interacts directly with the code
What do I want from my tests:
How to start
Start with a simple test with a name similar to the class name, then add more details as you gain more insight of what you actually want to test.
Later on you can rename the first test method to make it more specific.
“One of the biggest benefits of working with a Test Driven Approach is that the tests give you a good place to play with the code and figure out exactly what you want to land in terms of design.“
Asserting Exceptions
Asserting exceptions with
try
/catch
&&fail
instead of@expectedException
gives you the opportunity to execute more assertions on the exception object itself.Reduce duplication in your tests
To remove duplication in different test methods you can overwrite the
setUp
method to store common values as properties, replace bindings in the Laravel Container, etc. For example:You can also create custom assertions or test helpers, for example:
Additional Tips
💡 Make the tests folder match the folder structure of your application
💡 Hide Eloquent details from the controllers (Extract to new methods and unit test those methods).
Limiting Ticket Sales
💡 Include an assertion in your arrange test in order to verify that a precondition is met.
💡 When you explicitly update a column in another model, example:
$ticket->update([‘order_id’ => null])
You can use that opportunity to create an explicit and more readable method in that model, example:
$ticket->release()
.You might also want to unit test that method.
💡 Sometimes you might want to add redundant test coverage in order to get more explicit error messages when the tests fail. However as a downside the test suite might be slower and this might increase the work to maintain the tests suite.
The text was updated successfully, but these errors were encountered: