A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearTagging unit-tests - page 1
User InfoPosts
Tagging unit-tests#1
I(m working on a PHP project with solid unit-tests coverage.

I(ve noticed, that last time, I(m making very tricky manipulations with unit-tests Command-Line Test Runner( --filter command.

Here is this command(s explanation from official documentation:



--filter

Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names.



I ofter use it because sometimes it becomes very useful to run just a single test suite or test case from the whole test base.

I(m wondering if this is good practice or not?

I have heard that sometimes it is good practice to to run the whole test suite on your Continuous Integration machine, if you know for sure that you have modified only one component and 100% percent confident, that it won(t fail other component(s unit-tests.
What do you think about it?

Some time ago I thought that we shouldn(t care so much about time require to run the whole suite of all unit-tests, but when you have very complicated business logic and unit-tests - this can take significant time.

I understand, that "real" unit-tests shouldn(t interact with DB, use mock/stubs objects, I agree with that. But sometimes, it is much easier(cheaper) to use DB fixtures for the tests.

Please give me some advice, how this problem can be solved?

posted date: 2009-04-12 13:13:00


Re: Tagging unit-tests#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-12 13:13:01


Re: Tagging unit-tests#3
Good unit tests should: Have clear methods names and variable names to act as documentationRun fast. This will also be possiblefor test with complicated businesslogic. Test should run in an avaragetime of something around 0.1 second.Test exactly one thing in one test methodNot integrate with external resources like the filesystem, email,databases, webservices, andeverything else. You can createseperate database integration teststo test your database ineraction.These test will slower then your unittest most of the time. I put myintegration tests in a seperateproject and I run them only when I amworking on the integration code. Ialso run them on all builds on the CIserver. Be completely isolated from each other. When you have tests dependingon each other, you cannot see whatyour problem is from reading whichtests are failed. You might have todebug to find the problem. Isolatedtests will save you a lot of time.Personally, I don(t use category names in my tests. I use 2 test projects per application. One for the unit test and one for the integration tests and slower tests. Reaction on: "But sometimes, it is much easier(cheaper) to use DB fixtures for the tests."When your code is written well, it will be easier to mock. I don(t know about mocking frameworks in Php, but I use them in other languages to save me a lot of time. Writing test first and code later might help you to design your code to be testable easier.Personally I learned to test better byreading blogs about itreading books about itreading tested code written by otherswriting a lot of tests of course. It took me a few thousends of tests to become good at it.

posted date: 2009-04-12 14:38:00


Re: Tagging unit-tests#4
hm.. Very new idea to me about splitting fast and slow tests into different project. And very interesting too. It looks more like tests are slow because of the they are not unit-tests but integration tests, as you said before. Thank you

posted date: 2009-04-12 14:43:00


Re: Tagging unit-tests#5
I ofter use it because sometimes it becomes very useful to run just a single test suite or test case from the whole test base.I(m wondering if this is good practice or not?Sure, as long as you run the full set of unit-tests occasionally (via a CI server sounds perfect)Running the "interesting" tests regularly is better than running all the tests rarely..

posted date: 2009-04-12 15:07:00


Re: Tagging unit-tests#6
I(d address the issue by having a subset of tests ("smoke tests") that take 1 minute or less that must be run before committing, then run the full set of tests from your CI server.If your full set of tests takes > 15 minutes then I(d look to divide them and run them in parallel.Then you can use the --filter to run the tests you(re most interested in first, then the smoke tests prior to commit, and have the rest run from the CI server.

posted date: 2009-04-13 10:37:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.