Answers.Body: <p>Agree that the typical configuration is to have a separate, headless database for running tests.</p>
  
  <p>Your problem sounds similar to (but slightly different from) the problem of running unit-tests provided by extensions. In both cases, one wants to activate the extension on the headless database, so we may borrow some techniques from extension testing.</p>
  
  <p>If I were you, I'd try preparing a DB snapshot with the extension preinstalled, e.g.:</p>
  
  <pre><code>cd ~/buildkit/build/mybuild
  
  
  # Put the extension source code somewhere under `civicrm`, e.g
  git clone https://mygit.example.com/myextension sites/all/modules/civicrm/tools/extensions
  
  
  # Activate the extension in your main DB, e.g.
  drush cvapi extension.install key=com.example.myextension
  
  
  # Update the DB snapshot for your build
  civibuild snapshot mybuild
  
  
  cd sites/all/modules/civicrm/tools/extensions
  
  # Restore DB &amp; run tests at the same time
  civibuild restore mybuild &amp;&amp; ./scripts/phpunit CRM_AllTests
  </code></pre>
  
  <p>Each time you restore the DB, it resets both the main DBs (Civi+CMS) as well as the headless test DB using the latest snapshot.</p>
  
  <p>You can repeat the last command whenever you want to run the tests. This ensures that the extension is active (even if some test went mucking around with extension data).</p>
  
  <p>You can change <code>CRM_AllTests</code> to <code>api_v3_AllTests</code>, <code>api_v3_SyntaxConformanceTest</code>, <code>CRM_Myextension_MyTest</code>, or any other test class.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-23T19:51:10.543Z
Answers.LastActivityDate: 2015-11-23T19:51:10.543Z
Answers.UserDisplayName: Tim Otten
Body: <p>(Please note - I am not asking how to create unit tests for an extension.)</p>
  
  <p>If I want to see how an extension - or combination of extensions - impacts CiviCRM's functionality, I think it'd be really neat to run the standard UTs (thanks buildkit &amp; vagrant :) with an extension installed.</p>
  
  <p>My understanding at the moment is that Civi Unit Tests initialise a new copy of the DB when they're run, and mess about with it a lot.</p>
  
  <p>Please can anyone tell me where/when I should hook in enabling extension functionality?</p>
  
  <p>John</p>
  
Tags: <civicrm-buildkit>
Title: Running CiviCRM unit tests with an extension installed
ThreadText: # Running CiviCRM unit tests with an extension installed
  
  (Asked by: username_0 on 2015-11-23)
  
  (Please note - I am not asking how to create unit tests for an extension.)
  
  If I want to see how an extension - or combination of extensions - impacts CiviCRM's functionality, I think it'd be really neat to run the standard UTs (thanks buildkit & vagrant :) with an extension installed.
  
  My understanding at the moment is that Civi Unit Tests initialise a new copy of the DB when they're run, and mess about with it a lot.
  
  Please can anyone tell me where/when I should hook in enabling extension functionality?
  
  John
  
  **Tags:** civicrm-buildkit
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-23. Score: 2 | Accepted answer
  
  Agree that the typical configuration is to have a separate, headless database for running tests.
  Your problem sounds similar to (but slightly different from) the problem of running unit-tests provided by extensions. In both cases, one wants to activate the extension on the headless database, so we may borrow some techniques from extension testing.
  If I were you, I'd try preparing a DB snapshot with the extension preinstalled, e.g.:
  cd ~/buildkit/build/mybuild
  
  
  # Put the extension source code somewhere under `civicrm`, e.g
  git clone https://mygit.example.com/myextension sites/all/modules/civicrm/tools/extensions
  
  
  # Activate the extension in your main DB, e.g.
  drush cvapi extension.install key=com.example.myextension
  
  
  # Update the DB snapshot for your build
  civibuild snapshot mybuild
  
  
  cd sites/all/modules/civicrm/tools/extensions
  
  # Restore DB & run tests at the same time
  civibuild restore mybuild && ./scripts/phpunit CRM_AllTests
  
  Each time you restore the DB, it resets both the main DBs (Civi+CMS) as well as the headless test DB using the latest snapshot.
  You can repeat the last command whenever you want to run the tests. This ensures that the extension is active (even if some test went mucking around with extension data).
  You can change CRM_AllTests to api_v3_AllTests, api_v3_SyntaxConformanceTest, CRM_Myextension_MyTest, or any other test class.
  
  
  ---
  
  