Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-27T02:50:09.657Z
Answers.Text: 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?
Answers.UserDisplayName: Andy Moreno
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-27T03:02:20.710Z
Answers.Text: 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...
Answers.UserDisplayName: Andy Moreno
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-27T21:23:19.040Z
Answers.Text: 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?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T04:53:05.950Z
Answers.Text: Yes, exactly. How do I trigger Codeception (from the root app?) to test inside an installed plugin?
Answers.UserDisplayName: Andy Moreno
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T21:48:35.200Z
Answers.Text: 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?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-29T01:02:07.903Z
Answers.Text: 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?
Answers.UserDisplayName: Andy Moreno
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-29T21:07:38.210Z
Answers.Text: "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 ...`
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-26T18:00:30.567Z
Answers.LastActivityDate: 2021-04-26T18:00:30.567Z
Answers.UserDisplayName: Brad Bell
Body: <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>
  
Tags: <setup><tests>
Title: How do you unit test plugins?
ThreadText: # 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 username_1, 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 ...`  
  
  ---
  
  