2

I have Codeception running on my local install without errors, but it's not yet actually doing anything. I am building several plugins and I can't figure out how you actually test a plugin? I have no app code at all, all functionality comes from the plugins.

I have seen other plugins running their own custom PhpUnit code inline, but shouldn't I be able to fire off Codeception from the root app and it will test available plugins?

Fully aware that this is a vague question, but I can't find any information about specifically testing Craft plugins.

2

Have you been through Craft's testing documentation? https://craftcms.com/docs/3.x/testing/

There's a pretty good walkthrough of the necessary steps there to test plugins: https://craftcms.com/docs/3.x/testing/testing-craft/setup.html

Or if you like more real-world examples, Commerce's tests are a good place to start: https://github.com/craftcms/commerce/blob/develop/codeception.yml

From then, you'd trigger all unit tests from the root of your project like:

./vendor/bin/codecept run unit

Or every test in a single file with:

./vendor/bin/codecept run tests/unit/helpers/LocaleHelperTest.php

Or a specific test within a single file with:

./vendor/bin/codecept run tests/unit/helpers/LocaleHelperTest.php:testEmailGetOrderLanguage
7
  • Hi Brad, yes I have been through all the testing documentation that I've found, and like I mentioned I managed to get Codeception running without too many issues. What I am struggling with is actually getting into the plugin itself, I would expect all the plugin testing code to live inside the plugin, not in the app root? I see your example above and that doesn't look like it has anything to do with a plugin? Apr 27 at 2:50
  • I guess what I'm saying is that I don't understand the full idea about the structure of a root app with active plugins available for testing. I wouldn't expect the plugin to have it's own config settings, those should come from the app, and so on. I haven't found any article that describes this full setup... Apr 27 at 3:02
  • Sorry if I'm not following... do you have a plugin you're building in its own repo similar to github.com/craftcms/commerce?
    – Brad Bell
    Apr 27 at 21:23
  • Yes, exactly. How do I trigger Codeception (from the root app?) to test inside an installed plugin? Apr 28 at 4:53
  • Maybe not exactly... it sounds like you're wanting to test a plugin from a Craft site. i.e. you installed Craft from github.com/craftcms/craft, installed a plugin (via whatever means), and want to unit test it from where it lives in the vendor folder? Instead of wanting to test the plugin directly from the source of the plugin repo?
    – Brad Bell
    Apr 28 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.