title: Right way to seed MongoDB for automated testing with Karate
body: <p>I'm building an automated API testbed and I've chosen Karate for the job. Too bad its engine is written for a Java ecosystem, where the community support for mongoDB technology is not that strong as for NodeJS</p>
  
  <p>Since I need to seed/cleanup DBs In QA environment to execute tests, but I just have a seeding script made with NodeJS and a specific library, so now I have two opportunites</p>
  
  <ol>
  <li><p>Keep using a NodeJS init script where my DB is populated before running Karate tests</p></li>
  <li><p>Use a Java seeding library that enables fixture loading from files (ex. JSON) or from DB dumps and execute the seed before each feature with JUnit hooks</p></li>
  </ol>
  
  <p>Both alternatives should enable devs/qas to build multiple fixtures and select which one is suited for a certain set of feature tests. For instance, in the scenario #1 i could write a sh script that does</p>
  
  <pre><code>npm run seed
  mvn clean test
  </code></pre>
  
  <p>But it lacks control from qa on which data to load (unless you don't specify it in this shell script, which means that must be updated often and must "know" which features are implemented and when to run them). The other downside is that CI server must have nodeJS installed and the pipeline configuration must know it, and CI servers should not have many tools installed on</p>
  
  <p>Any advice?
  Thanks</p>