Test-Driven Development in CakePHP - cakephp

I'm using CakePHP 2.3 and would like to know how to properly go about building a CakePHP website using test-driven development (TDD). I've read the official documentation on testing, read Mark Story's Testing CakePHP Controllers the hard way, and watched Mark Story's Win at life with Unit testing (PDF of slides) but am still confused. I should note that I've never been very good about writing tests in any language and don't have a lot of experience with it, and that is likely contributing to my confusion.
I'd like to see a step by step walkthrough with code examples on how to build a CakePHP website using TDD. There are articles on TDD, there are articles on testing with CakePHP, but I have yet to find an in-depth article that is about both. I want something that holds my hand through the whole process. I realize this is somewhat of a tall order because, unless my Google-fu is failing me, I'm pretty sure such an article hasn't yet been published, so I'm basically asking you to write an article (or a long Stack Overflow answer), which takes time. Because this is a tall order, I plan to start a bounty on this question worth a lot of points once I'm able to in order to better reward somebody for their efforts, should anybody be willing to do this. I thank you for your time.

TDD is a bit of falacy in that it's essentially just writing tests before you code to ensure that you are writing tests.
All you need to do is create your tests for a thing before you go create it. This requires thought and analysis of your use cases in order to write tests.
So if you want someone to view data, you'll want to write a test for a controller. It'll probably be something like testViewSingleItem(), you'll probably want to assertContains() some data that you want.
Once this is written, it should fail, then you go write your controller method in order to make the test pass.
That's it. Just rinse and repeat for each use case. This is Unit Testing.
Other tests such as Functional tests and Integration tests are just testing different aspects of your application. It's up to you to think and decide which of these tests are usefull to your project.
Most of the time Unit Testing is the way to go as you can test individual parts of the application. Usually parts which will impact on the functionality the most, the "Critical path".
This is an incredibly useful TDD tutorial. http://net.tutsplus.com/sessions/test-driven-php/

Related

Advice and experience for testing a CN1 app

I would like to start automating the testing of my app written in CodenameOne, but I find it difficult to visualize how to use the TestRecorder (section "Unit Testing") for "industrial" testing.
If anyone here is already using it, could you share a few tips about how you use it?
E.g. how do you use the different "Asserts" buttons, how do you structure your tests into suites and how do you chain them together (e.g. so each test case will start in the right context like where in the navigation structure it is supposed to run), do you need to manually edit the tests, ... And is there anything to be aware of before creating lots of tests interactively, e.g. to avoid that your tests are invalidated by some irrelevant change to your UI?
I read in the blog post from May 2017 that the TestRecorder "wasn’t picked up by many developers and as such it stagnated". I tried TestRecorder and immediately came across a seemingly basis error in it (missing test for null) when recording a test case using the Toolbar, which gave the impression it is still the case. So, if anyone here is using another approach that is working well for you, I'd love to hear about that.
See the test classes we use to test Codename One itself here: https://github.com/codenameone/CodenameOne/tree/master/tests/core
You can use the test recorder to generate a skeleton but you can do this manually just like any test. The test API lets you invoke the app or just pieces of it and perform assertions on the behaviors within.

How to begin writing code for e2e testing in ionic ?

I am new to ionic and decided that i wanted to integrate testing while building my app. But I am a little confused.
Should i write a test after already written functions? or functions that I will write?
Should I test every function ?
I would appreciate if someone just explains the logic flow for me.
Well, you could look into TDD (Test Driven Development) and that should answer your questions.
However, to provide a short answer here as well; you should write a test first, code later (for the why consult the link above). In practice, testing every function may not be viable, but TDD certainly enforces it.
One thing to note, you wrote E2E, but actually what you'll be doing at the start is Unit Testing your functions (E2E comes later).

Where and what is my unit test?

I have been reading tons of articles on unit testing. I am specifically using angular.js right now and came to the conclusion that unit testing = great. I also understand what unit tests are conceptually, but I honestly have no idea what I am doing or looking for. I already started the angular application and before I continue, I feel like I should start testing units of it. I have started tutorials and everything tells me "how" to do it using jasmine (or the other ones). I have a node project set up that is running Karma and a folder that has some *.js files in it to do all the describing/testing. However, it feels like the "tests" I write in a js sit in that file and do nothing.
What am I looking for? How do I actually view the results of the tests? It is all there, but I have no idea where exactly I am supposed to start. Am I supposed to be able to view the test in the browser? Is it supposed to run and save to a log file? Is it actually supposed to be tied to my ACTUAL code, or is it just rewritten logic that is supposed to mimic my code for testing?
This may be a dumb question, but I have spent a long time trying to figure out what exactly to look for. I noticed in some tutorials people have had little windows that tell them if their tests are failing or not (webstorm I believe) while they are writing the tests.
Any guidance would be greatly appreciated!

Starting work on a Pre-existing Project

So this is more of a generic question. I seem to keep finding myself being put on larger and larger projects. Recently I have been assigned to a very large project written in C and VHDL. The goal is for me to become familiar with the code and eventually take the lead on the project. This is by far the largest project I have been assigned to work on that I didn't start.
So here is my question: What methods/tools do you use to learn how everything works?
Do you just increase and expand on comments?
Do you make a UML representation of the project?
Any tips would be great!
Thanks
If you can, sit down with the folks who are currently working on it and ask for a high-level solution overview to start and then go on your own from there, digging into the pieces one by one. Identify who is responsible for each functional area and follow up with them when you hit a rough spot.
Try and embed yourself with the team as quickly as possible, ask to sit in on code reviews and such. This will get you ramped up pretty quickly.
For VHDL I recommend using Sigasi. Sigasi is developped with this use case in mind. Sigasi makes it easy to navigate in new or legacy projects, which makes it feasible to understand how it is structured.
I find the UML almost useless. I find much more useful, real, static and dynamic call graphs. After I generate the call graph, I usually grok the source code through OpenGrok and cscope. See what calls what and what is called by whom for the most hot methods.

Best screen scraper, simple html dom or snoopy?

which one is better for screen scraping? simple html dom or snoopy ??
i use simple html dom and find it comfortable..
does snoopy has any advantage over simple html dom?
my requirements : if i wanna scrape contents from a page(after login)..
simple html dom is easy but it takes a lotta time to print the results..
Is Snoopy that well known / mature of a package?
If it's not, then all other things being equal, I'd probably go with generic HTML DOM code - especially if the scraping is somewhat simple.
But only you know when your code is starting to get too big, unmanageable, etc., at which point it might be better to look at another tool out there like Snoopy.
(Which, admittedly, I don't have experience with; it's apparently at http://sourceforge.net/projects/snoopy/ for those not familiar with it - "Snoopy is a PHP class that simulates a web browser. It automates the task of retrieving web page content and posting forms, for example.")
The real reason I'm posting, even though I don't know Snoopy per se and thus can't definitively answer your question, is to ask if you've considered using Selenium (http://www.seleniumhq.org/) instead of Snoopy.
Selenium is a fairly well-known testing tool, and it occurred to me that one of the nice things about using that for what you're doing (if you can) is that it has built in tests.
The reason that's good is that screen scraping is kind of an inherently brittle task - if the target site changes something, blam, your scraping fails. So it's kind of a nice design to have an automated scrape/test-that-scraping-worked system.
Something to think about, anyway.
I've stumbled into BeautifulSoup, which is Python-based. I suppose there are a bunch of others too.
Looks like Snoopy is PHP-based, and hence can be run server-side only. Is this what you are really looking for? What are your requirements? Please elaborate on that.

Resources