Yii Framework Forum: How to write test dependencies in Yii - Yii Framework Forum

Jump to content

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

How to write test dependencies in Yii Rate Topic: -----

#1 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 543
  • Joined: 21-June 10

Posted 21 November 2010 - 10:00 AM

Hello, currently I am learning to write a test unit for my application.
I write a test function that depends on other test function. So it must running the first test and continue to second test.
I am trying to write like this

public function testConfirm(){
  ...
   $student = $this->student('first');
}

        /**
     * @depends testConfirm
     */
public function testUnConfirm(){
     ....
     $student->unconfirm(); //<= it doesn't recognise the $student.
}


but unfortunately it's not working. Did I miss something?
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,080
  • Joined: 17-January 09
  • Location:Russia

Posted 21 November 2010 - 11:08 AM

Make student a private class member.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 543
  • Joined: 21-June 10

Posted 21 November 2010 - 11:35 AM

View Postsamdark, on 21 November 2010 - 11:08 AM, said:

Make student a private class member.


But as far as I know, PHPUnit provide annotation of @depends to make dependencies test
I read it from here : PHPUnit Documentation
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,080
  • Joined: 17-January 09
  • Location:Russia

Posted 21 November 2010 - 02:05 PM

Yes. test1 @depends test2 means "don't even try to run test2 if test1 failed".
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   galymzhan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 27-October 10
  • Location:Алматы

Posted 21 November 2010 - 03:02 PM

I think you could do:
public function testConfirm(){
   $student = $this->student('first');
   //...
   return $student;
}

/**
 * @depends testConfirm
 */
public function testUnConfirm($student){
     $student->unconfirm();
}

2b || !2b that's the question
0

#6 User is offline   jacmoe 

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

Posted 21 November 2010 - 03:11 PM

Isn't the whole point of unit tests that they are *units*, ie self-contained. ?
They shouldn't depend on a previous test, or am I wrong?
"Less noise - more signal"
0

#7 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 543
  • Joined: 21-June 10

Posted 21 November 2010 - 08:34 PM

Ahh.. I see..
I've finally understood..
Thanks samdark & galymzhan..

@jacmoe,
well, I think in most case we need dependencies test. Supposed we want to test create and delete. It's faster to test the create first, and get that result, to test in delete case.
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#8 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 22 November 2010 - 04:15 AM

Also see the notes here (Test Dependencies):
http://www.phpunit.d...or-phpunit.html
0

#9 User is offline   Andres Felipe Diaz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 13-August 12

Posted 12 February 2013 - 05:04 PM

If you guys are using Netbeans and use the code snippet /* [Enter]

to create your comments it will do them like this:

/*
*
*/

If you add the @depends annotation it will look like this but will not work.

/*
* @depends test
*/

This is because your freacking block comment needs the two stars at the top in order to recognize the annotations. This is a small detail but I was stuck here until I noticed the second star missing. Your code should look like this:

/**
* @depends test
*/
Andrés Felipe Díaz
Andrés Felipe Díaz Digital Geek Blog Trickortip.com
My LinkedIn Profile
0

#10 User is offline   BenBenBenBen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 30-September 13

Posted 16 October 2013 - 09:25 PM

View PostAndres Felipe Diaz, on 12 February 2013 - 05:04 PM, said:

If you guys are using Netbeans and use the code snippet /* [Enter]

to create your comments it will do them like this:

/*
*
*/

If you add the @depends annotation it will look like this but will not work.

/*
* @depends test
*/

This is because your freacking block comment needs the two stars at the top in order to recognize the annotations. This is a small detail but I was stuck here until I noticed the second star missing. Your code should look like this:

/**
* @depends test
*/

You are right,I meet the same problem,and it works now
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