Yii Framework Forum: Gii should generate Unit tests as well - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Gii should generate Unit tests as well

#1 User is offline   Bergtroll 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-August 09

Posted 13 April 2012 - 05:39 AM

As the title says I think its a good idea if the generators would not only generate the production code itself but also the initial unit tests. Its quite a big burden and from a more philosophical point of view also in injury of the agile manifesto if I generate 10.000 lines of code without generating the tests for it, as well as writing the tests for this 10.000 lines of code upfront because that would violate "Write only as much test code as needed to fail". In my opinion the only solution really is generating the unit tests aside. What do you think?
4

#2 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 13 April 2012 - 06:46 AM

I think that's a good idea. But I wouldn't include any tests, just create the basic "skeleton" for own tests including fixture files for models (again, no data needed, just a fixture array that can easily be changed by the developer). These are the steps you would do anyway in 99,9% of all cases. Why no initial test creation? Because then you are effectively testing Yii if I understand you correctly, not your own code and one should assume that Yii is properly tested already.

EDIT: Wait. There are parts that are frequently customized by the developer and therefore could need an initial test like attributeLabels() etc.
0

#3 User is offline   Bergtroll 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-August 09

Posted 13 April 2012 - 07:54 AM

I'd guess the Yii unit tests are testing the code generators and Yii classes itself. But everything generated for you is not Yii core but part of your own projects code base afterwards. Consequently there should be generated unit tests that covers all the generated code. Of course if you never ever touch the code being generated there would be no added value above testing the validity of the generators itself. This is a quite unrealistic scenario, and as soon as you change anything in the generated production code, you are in danger of breaking something at an unexpected place. Therefore changing generated code instantly leads to the need for unit test coverage of the generated code.

Furthermore I agree with you that it would be an amazingly helpful feature, to generate fixture skeletons for ActiveRecords as well.
0

#4 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 13 April 2012 - 08:23 AM

I see and I am totally with you.
0

#5 User is offline   ololo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 23-January 11
  • Location:Minsk, Belarus

Posted 13 April 2012 - 10:09 AM

don't think this problem should be solved by core team, gii is extensible so yii users can solve such particular problems (as phpunit/codeception/behat test mocks generation) and share their solutions as extensions

some people prefer to extend generated classes with their own, in this case unit tests for generated classes are rather undesirable
0

#6 User is offline   Tropi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 30-November 11

Posted 14 April 2012 - 04:26 PM

View Postololo, on 13 April 2012 - 10:09 AM, said:

don't think this problem should be solved by core team,

I don't think so. There are many reasons why this should be done, the two most important:
- it's a feature that every (serious) application needs
- it enforces people - who don't already do so - to create unit tests, leading to more stable software overall.
0

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 14 April 2012 - 04:49 PM

The problem is that it forces me to use PHPUnit - and I really don't like it much.

Extend Gii if you want.
That's exactly the reason why it's extendable.

I don't want anything enforced on me. ;)
"Less noise - more signal"
0

#8 User is offline   Ivica 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 317
  • Joined: 25-May 11

Posted 15 April 2012 - 12:06 AM

Well, there can be few issues. What if somebody follow TDD practice, which means that tests should be generated first, so, generating tests when models/controllers are created will not help.
I also think it is more safe when you generating tests manually, because sometime you don't want to test some functions/features, that might already be tested, or for example you want to have two test function for one say model function(for example with regular and with invalid parameters, in case when your tests are very big, and you want to split them into two tests).
Zurmo: Yii Powered Open Source CRM
zurmo.org
0

#9 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 18 July 2012 - 04:39 AM

I think I know a solution: PHPUnit has an addition called sekeleton generator. All it does is to generate a skeleton full of test methods marked as incomplete. I think gii could provide a template featuring the very same, as the skeleton generator's code is pretty simple. It forces you to nothing but will allow you to rapidly create the skeletons out of gii without having to touch PHPUnit.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#10 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 18 July 2012 - 09:19 AM

use yiic
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users