Comments (8)
I don't know if you already learned about this on your own but here's my $0.05:
Unit testing as I understand it is part of a development philosophy called Test-Driven Development (TDD). In TDD, you write a test for a feature that you plan to implement FIRST before you write the feature itself. The test fails (because the feature is not there yet). Then you write the minimal amount of code to make the test pass. You keep writing tests and writing code, making sure all previous tests keep passing.
For example, a feature request currently exists on the site called "allow image upload from URL."
- You would first write a Selenium test that would look for an "upload from URL" button or something like that. It wouldn't find the button, so it would fail. You would then create the button and the test would pass.
- You would then write a test where Selenium enters an image a URL and tries to upload it. It would fail, then you would add the upload-through-URL feature, and it would pass.
- Then you would enhance the UI look of the button and run the tests again. Now they fail, what happened? Turns out you forgot to close a
<div>
tag and now the whole UI is out of whack. Unit tests help you make sure new additions don't break anything in an automated way.
I want to learn more about the Laravel framework and contribute, but there's never enough time. :(
from infinity-next.
That's a really good synopsis, thank-you for taking the time to write it out.
I've been putting this off since day one, but I'm writing out a feature for administrative config now. I'll see if I can add some unit tests for that. I think Laravel has a built-in way of doing unit tests, so this is a good excuse to try it out.
from infinity-next.
Unit testing is difficult to get into, but is very rewarding! If you're interested in a book on unit testing, I can recommend "Extreme Programming" by Kent Beck. That book was what inspired me to really commit and start writing the tests for everything.
from infinity-next.
I did Test Driven Development recently, for my Software Engineering class, and I definitely recommend it.
Adding to what @panasenco said, TDD was very rewarding when we needed to refactor code. Changing lots of code can be scary, but not so much when you have lots of tests to help you debugging and understanding whether the new code is working 100% or not
It also helps you understand the quality of your program based, as you can simply check the percentage of tests that pass and fail. However, that implies the tests are good and thorough. They can be seen as requisites of your program - if you want your program to do X, test the X functionality and make sure it passes.
from infinity-next.
@panasenco If you'd like to look at commits 21a3333 and b413875, this is my attempt at doing unit tests. I'd like input before going out into other unit tests.
............
Time: 2.12 seconds, Memory: 26.75Mb
OK (12 tests, 45 assertions)
from infinity-next.
@jaw-sh These look great to me! I like that you wanted to make sure the response codes were correct before doing anything else. The next step would be to add extra tests that test functionality (is this element on the page that the user is navigated to?). Awesome start IMO!
from infinity-next.
@panasenco That's a good idea. Interestingly, this already helped me resolve a bug. Board logs had become broken with recent changes because they referenced a template which requires data the controller doesn't supply. When I saw a 500 error for that assertion it made me laugh.
This whole thing is brilliant. At my old job, which had hundreds of views and zero unit tests, it was a continuous game of whack-a-mole because new features would break old ones and we'd not notice until a client complained.
from infinity-next.
Haha it's great to see another convert. :D
from infinity-next.
Related Issues (20)
- Support x-i2p-desthash header HOT 2
- laravel wants missing rev-manifest.json HOT 2
- config.json doesn't work HOT 4
- Scrolling images on chrome mobile is impossible. HOT 2
- SVGZ support HOT 2
- I believe that one can in fact sell AGPL code. HOT 3
- Call to undefined method Illuminate\Database\Schema\Blueprint::inet() HOT 5
- npm install error HOT 2
- Parse error: T_THROW HOT 1
- Ability for BOs to sort stickied threads? HOT 2
- Two Errors encountered during install on a fresh 14.04 server HOT 2
- syntax error, unexpected 'throw' (T_THROW) HOT 4
- "php artisan migrate" spews out error HOT 1
- Trying to configure and install to a new website HOT 1
- Secure tripcodes HOT 4
- Broken installation HOT 1
- racist site https://9chan.tw/coalfax/catalog
- Exception details plz check HOT 4
- Classic IB post form
- This program should adopt the MFEK AGPL Flood Exception
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from infinity-next.