How to run units test of one application?

Hello everyone :slight_smile:

I am testing the groupfolder apps to offer groupfolder’s developers a enhancement. For my tests, I use this app (groupfolder) in my local machine and on one server. I am testing on both.
Before to modif the code of groupfolders app, I am testing with units test.
But I have encountered a problem when I launch this command on my local machine and server since last friday.

./vendor/bin/phpunit tests/Folder/FolderManagerTest.php

Here is the result on both enviromnents :

PHPUnit 8.5.14 by Sebastian Bergmann and contributors.

EEEEEEEEEEEEE                                                     13 / 13 (100%)

Time: 402 ms, Memory: 4.00 MB

There were 13 errors:

1) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testCreateFolder
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

2) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testSetMountpoint
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

3) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testAddApplicable
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

4) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testSetPermissions
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

5) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testRemoveApplicable
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

6) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testRemoveFolder
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

7) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testRenameFolder
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

8) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testSetACL
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

9) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testGetFoldersForGroup
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

10) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testGetFoldersForGroups
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

11) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testGetFoldersForUserEmpty
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

12) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testGetFoldersForUserSimple
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

13) OCA\GroupFolders\Tests\Folder\FolderManagerTest::testGetFoldersForUserMerge
Error: Class 'OC' not found

/var/www/html/nextcloud/dev-nc20.test.arawa.fr/apps/groupfolders/tests/Folder/FolderManagerTest.php:52

ERRORS!
Tests: 13, Assertions: 0, Errors: 13.

I don’t know where is the problem ? How to run units test of one application ?

I know the OC namespace is in the nextcloud/server repository. So I understand why it doesn’t work on my local machine but I don’t understand on the server.

What is more, I created one issue on this problem : How I run tests on my local machine ? · Issue #1299 · nextcloud/groupfolders · GitHub .

What is more, I modified the composer file adding the autoload :

// ...
    "autoload": {
        "psr-4": {
            "OCA\\GroupFolders\\": "lib/",
            "OCP\\": "vendor/christophwurst/nextcloud/OCP"
        }
    },
//...

I don’t know if I can add the psr-4 to autoload classes (?)

I don’t know where can I ask for help, so I am sorry in advance ^^’

see groupfolders/phpunit.yml at master · nextcloud/groupfolders · GitHub and the rest of the file. I think that should give you an idea of how to run the tests

more broadly there isn’t just one way to test an app, this unfortunately works differently from application to application.

Thanks :slight_smile:

I understand there are the check and setup steps .

But I have an 255 error code when I executed ./vendor/phpunit/phpunit/phpunit -c tests/phpunit.xml command.

Okay, for each app there is one way to test it. By unit test or with the browser, for example?

Broadly, as a developer I can ask to help here or on issues or both ? ^^’

You can use this forum but not all developers are active here :slight_smile:

Nice :slight_smile:

I don’t know if I create an issue to ask or to inform of a problem ^^’

I hope itsn’t embarrassing ^^’

Hey @ChristophWurst :slight_smile:

If I would like to improve the groupfolder project.

Should I write the unit test before pull request ? Or can I ask groupfolders’ developers help me on units tests ?

I’m not involved in groupfolders development, hence I can’t give any answer on this

I don’t think they would mind unit tests, but I’m afraid there is nobody around who has time for mentoring at the moment.