3 Replies - 890 Views - Last Post: 30 March 2015 - 12:19 PM

#1 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,020
  • Joined: 08-June 10

[PHPUnit] organise large test set

Posted 18 March 2015 - 01:23 PM

Hello,

I’m currently working on a class with a lot of methods (~30), hence the unit test would contain a lot of test cases (200+). Would it still be feasible to put all those tests into a single PHPUnit test class (which then would get veeery long) or should I split it into several test classes (e.g. one class per method)?

Dormi

This post has been edited by Dormilich: 18 March 2015 - 01:24 PM
Reason for edit:: correcting the number

Is This A Good Question/Topic? 0
  • +

Replies To: [PHPUnit] organise large test set

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1469
  • View blog
  • Posts: 8,176
  • Joined: 07-September 06

Re: [PHPUnit] organise large test set

Posted 18 March 2015 - 02:33 PM

I can tell you what I normally do, but I am not sure if it is what the most of the industry does... I typically break my tests up in to suites, and those suites each test a specific part of the functionality with multiple test cases in them. This means that if I have a super large class with 10 methods that have varying functionality I may write 10 suites with multiple tests each.
Was This Post Helpful? 1
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 463
  • View blog
  • Posts: 820
  • Joined: 17-June 08

Re: [PHPUnit] organise large test set

Posted 19 March 2015 - 08:47 AM

As a rule of thumb, you can apply the same organizational principles to test code that you do to your application code. It may be a common pattern, but there's no law that says you have to have exactly one test class per application class. If the test class is getting too unwieldy, then by all means go ahead and break it up. You could also do one test class per method, or one for each logical feature, or something else entirely - whatever makes the most sense for your case. The exact scheme you use isn't that critical so long as the organization is consistent and it's easy to figure out where a particular test would be located.

However, you can also look at it from the other direction. Maybe the huge test class is an indication of other problems. Does the class under test really need to be that big? Maybe the solution is to refactor your application class into multiple smaller classes, in which case the test organization would take care of itself. (Not that I know one way or the other - I'm just playing devil's advocate here.)
Was This Post Helpful? 1
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,020
  • Joined: 08-June 10

Re: [PHPUnit] organise large test set

Posted 30 March 2015 - 12:19 PM

Quote

Does the class under test really need to be that big?

yes. see https://github.com/D...ed-array-object


anyways, thanks for your opinions. I think I can make something of it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1