From 15a3985fd6dd6ed1fb673dc59cda8f4887e42012 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Nov 2014 15:03:17 +0100 Subject: [PATCH 1/2] Add reference for TestCase class to docs --- developer_manual/app/testing.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/developer_manual/app/testing.rst b/developer_manual/app/testing.rst index 82b45d4de..11a253881 100644 --- a/developer_manual/app/testing.rst +++ b/developer_manual/app/testing.rst @@ -51,15 +51,17 @@ would look like this: .. code-block:: php container = $app->getContainer(); $this->storage = $storage = $this->getMockBuilder('\OCP\Files\Folder') @@ -84,3 +86,8 @@ would look like this: } } + +Make sure to extend the ``\Test\TestCase`` class with your test and always call the parent methods, +when overwriting ``setUp()``, ``setUpBeforeClass()``, ``tearDown()`` or ``tearDownAfterClass()`` method +from the TestCase. These methods set up important stuff and clean up the system after the test, +so the next test can run without side effects, like remaining files and entries in the file cache, etc. From 23a228b9ab97f02b6760c08039bedfd31c5878ba Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Nov 2014 15:09:11 +0100 Subject: [PATCH 2/2] Update test sample to use namespaces and extend the TestCase class --- developer_manual/core/unit-testing.rst | 46 +++++++++++++++++--------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/developer_manual/core/unit-testing.rst b/developer_manual/core/unit-testing.rst index 3fb7b7320..745436b72 100644 --- a/developer_manual/core/unit-testing.rst +++ b/developer_manual/core/unit-testing.rst @@ -35,37 +35,51 @@ Then you can simply run the created test with phpunit. An example for a simple test would be: -:file:`/srv/http/owncloud/apps/myapp/tests/testsuite.php` +:file:`/srv/http/owncloud/apps/myapp/tests/testaddtwo.php` .. code-block:: php - assertEquals(5, addTwo(3)); - } + protected function setUp() { + parent::setUp(); + $this->testMe = new \OCA\Myapp\TestMe(); + } - } - ?> + public function testAddTwo(){ + $this->assertEquals(5, $this->testMe->addTwo(3)); + } -:file:`/srv/http/owncloud/apps/myapp/tests/testsuite.php` + } + + +:file:`/srv/http/owncloud/apps/myapp/lib/testme.php` .. code-block:: php - +