CodeIgniter Forums
CodeIgniter Testing Guide - A New Book for Automated Testing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Learn More (https://forum.codeigniter.com/forumdisplay.php?fid=15)
+--- Thread: CodeIgniter Testing Guide - A New Book for Automated Testing (/showthread.php?tid=62949)

Pages: 1 2 3 4 5 6


RE: CodeIgniter Testing Guide - A new book coming soon - ignitedcms - 10-28-2015

Hi kenjis,

Can you explain if or how unit testing works with active record. I've read a lot of stuff saying it is next to impossible doing unit tests with active record. Would love to hear your opinions on this.


RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 10-28-2015

What do you mean by "active record"? And what do you want to test?
If you have sample code to test, show me, please.


RE: CodeIgniter Testing Guide - A new book coming soon - ignitedcms - 10-28-2015

Let me just first say, I have 0 zero experience in unit testing, so forgive me if I sound dumb.

It was more to do with searching and reading other stuff I noticed people bringing unit testing being a problem with active record.
For example:

Quote:In my experience unit testing Active Record entities is next to impossible

http://www.mehdi-khalili.com/orm-anti-patterns-part-1-active-record/

I don't fully understand what it means and whether or not it evens applies to codeigniter's active record.


RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 10-28-2015

Don't worry. This book is for you. ;-)

Quote:If one or more of the lines below sounds familiar, this book is perfect for you!
  • I have never written test code.
  • I want to write test code, but I don't know how.
  • I tried to write test code in the past, but I couldn't quite figure it out.

First of all, Active Record is a design pattern and the CodeIgniter 2.x's Active Record is not Active Record.
It is a Query Builder. So the Active Record was renamed to Query Builder in CodeIgniter 3.0.

Second, you don't have to worry about Active Record or not. And you don't have to stick to unit testing.
If unit testing is difficult, you could test with the database.

In the context of CodeIgniter 3.0, we can write unit tests for models. In other words, we can test models
without the database, using mock objects.

How to unit test models is explained in Chapter 6, which was released yesterday.

The answer to your question is like this:
  • It may be difficult to unit test Active Record entities, but is not impossible.
  • But I don't know unit testing them is useful or not. It depends on the code under test



RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 10-30-2015

Hi everyone!

Don't you like command line?

If you don't like CLI or terminal, do you want to know how to use PHPUnit via your web browser?


RE: CodeIgniter Testing Guide - A new book coming soon - solidcodes - 10-31-2015

command line is fine.
It's faster than web browser.

By the way I don't have camera for photos.
perhaps you can get/buy photos here.
http://www.istockphoto.com/


RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 10-31-2015

We have some candidates, but are still looking for a good photo for our book.

If anybody who knows about the book and finds a good photo for the cover image in the site like
http://www.istockphoto.com/ (it is needed that we can use the photo for our ebook cover
without copyright issues), let me know.


RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 11-06-2015

I will add additional explanation about how to run PHPUnit via web browser.
It is just addition and optional. If you like CLI, of course you don't need it.

I could release the update including it next week.

[Image: attachment.php?aid=396]


RE: CodeIgniter Testing Guide - A new book coming soon - kilishan - 11-06-2015

First off - that UI looks pretty nice. Looking forward to seeing it.

Second - I would love to see more info in the book about customizing the PHPUnit process itself. You've done a massive job of putting together elements in your CI PHPUnit Test, but more knowledge of what those files are, what they do, how to customize these things to our own process would be great.


RE: CodeIgniter Testing Guide - A new book coming soon - kenjis - 11-09-2015

Thank you for your feedback.

> more knowledge of what those files are, what they do

It seems very advanced topic. It is not suited for the beginners guide.
So I will add an appendix to explain about ci-phpunit-test code.