CakePHP Unit Testing Assign Name Conventions Argh?

I hit my head against the wall, trying to understand why I can not correctly install my device. When I try to run my test, my layout is displayed. If I comment out the device, the test will pass correctly. I went through this 100 times, and I can’t understand what’s wrong.

Heres my Videosview.test.php

App::import('Model','Videosview');

class VideosviewTest extends Videosview {
    var $name = 'Videosview';
    //var $useDbConfig = 'test_suite';
}

class VideosviewTestCase extends CakeTestCase {
    var $fixtures = array( 'app.videosview' );

    function testIncrementTimer() {
        $this->autoLayout = $this->autoRender = false;

        $this->Videosview =& ClassRegistry::init('Videosview');
        //$video_view = $this->find('first');
        $result = $this->Videosview->increment_timer($video_view['Videosview']['video_id'],$video_view['Videosview']['user_id'],1);
        $this->assertTrue(true);
    }
}

This is my videoview_fixture.php

class VideosviewFixture extends CakeTestFixture {
    var $name = 'Videosview';

    var $import = array('model' => 'Videosview', 'records' => true);
}
+3
source share
1 answer

There is a lot of weird code, it seems you don't understand how the tests are used. The problem is not from importing your appliance.

$ this-> assertTrue (true) will always return true. No need to declare a VideoviewTest.

, increment_timer, , , + 1:

function increment_timer($id = null){
    return $id++;
}

App::import('Model', 'Videosview');

class VideosviewTestCase extends CakeTestCase {
    var $fixtures = array('app.videosview');

    function startTest() {
        $this->Videosview =& ClassRegistry::init('Videosview');
    }

    function endTest() {
        unset($this->Videosview);
        ClassRegistry::flush();
    }

    function testIncrementTimer() {
        $input = 1;

        // let test increment_timer function by asserting true that return value is $input + 1, green bar
        $this->assertTrue( $this->Videosview->increment_timer($input) == ($input+1), 'Should return 2' );
        // let test increment_timer function by asserting false that return value is $input + 2, green bar
        $this->assertFalse( $this->Videosview->increment_timer($input) == ($input+2), 'Should not return 3' );
        //the following returns an error as return value is not equal to $input + 2, Red bar
        $this->assertTrue( $this->Videosview->increment_timer($input) == ($input+2), 'Should return 2' );
    }
}

, ,

Test screenshot

+1

Source: https://habr.com/ru/post/1725361/


All Articles