<p>Have you been through Craft's testing documentation? <a href="https://craftcms.com/docs/3.x/testing/" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/testing/</a></p>
<p>There's a pretty good walkthrough of the necessary steps there to test plugins: <a href="https://craftcms.com/docs/3.x/testing/testing-craft/setup.html" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/testing/testing-craft/setup.html</a></p>
<p>Or if you like more real-world examples, Commerce's tests are a good place to start: <a href="https://github.com/craftcms/commerce/blob/develop/codeception.yml" rel="nofollow noreferrer">https://github.com/craftcms/commerce/blob/develop/codeception.yml</a></p>
<p>From then, you'd trigger all unit tests from the root of your project like:</p>
<pre><code>./vendor/bin/codecept run unit
</code></pre>
<p>Or every test in a single file with:</p>
<pre><code>./vendor/bin/codecept run tests/unit/helpers/LocaleHelperTest.php
</code></pre>
<p>Or a specific test within a single file with:</p>
<pre><code>./vendor/bin/codecept run tests/unit/helpers/LocaleHelperTest.php:testEmailGetOrderLanguage
</code></pre>

CC BY-SA 4.0
2021-04-27T02:50:09.657Z
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?
Andy Moreno
CC BY-SA 4.0
2021-04-27T03:02:20.710Z
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...
Andy Moreno
CC BY-SA 4.0
2021-04-27T21:23:19.040Z
Sorry if I'm not following... do you have a plugin you're building in its own repo similar to https://github.com/craftcms/commerce?
Brad Bell
CC BY-SA 4.0
2021-04-28T04:53:05.950Z
Yes, exactly. How do I trigger Codeception (from the root app?) to test inside an installed plugin?
Andy Moreno
CC BY-SA 4.0
2021-04-28T21:48:35.200Z
Maybe not exactly... it sounds like you're wanting to test a plugin from a Craft site. i.e. you installed Craft from https://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
CC BY-SA 4.0
2021-04-29T01:02:07.903Z
Right, I see what you mean; but I am developing our own plugins locally, not inside the vendor folder, this is what I want to test. Should I just run Codeception in the root of my plugin folder, as if it was the app root?
Andy Moreno
CC BY-SA 4.0
2021-04-29T21:07:38.210Z
"Should I just run Codeception in the root of my plugin folder, as if it was the app root?" Correct - in the Commerce example in my answer (https://github.com/craftcms/commerce/), you'd run it right from the root of the repo using `./vendor/bin/codecept ...`
Brad Bell
CC BY-SA 4.0
2021-04-26T18:00:30.567Z
2021-04-26T18:00:30.567Z
Brad Bell
<p>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.</p>
<p>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?</p>
<p>Fully aware that this is a vague question, but I can't find any information about specifically testing Craft plugins.</p>

<setup><tests>
How do you unit test plugins?
# How do you unit test plugins?

(Asked by: username_0 on 2021-04-26)

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.

**Tags:** setup, tests


---

## 1 answers

### Answer by username_1 on 2021-04-26. Score: 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

> **Comments:**
> **username_0**: 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?  
> **username_0**: 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...  
> **username_1**: Sorry if I'm not following... do you have a plugin you're building in its own repo similar to https://github.com/craftcms/commerce?  
> **username_0**: Yes, exactly. How do I trigger Codeception (from the root app?) to test inside an installed plugin?  
> **username_1**: Maybe not exactly... it sounds like you're wanting to test a plugin from a Craft site. i.e. you installed Craft from https://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?  
> **username_0**: Right, I see what you mean; but I am developing our own plugins locally, not inside the vendor folder, this is what I want to test. Should I just run Codeception in the root of my plugin folder, as if it was the app root?  
> **username_1**: "Should I just run Codeception in the root of my plugin folder, as if it was the app root?" Correct - in the Commerce example in my answer (https://github.com/craftcms/commerce/), you'd run it right from the root of the repo using `./vendor/bin/codecept ...`  

---

