title: play 2 how to override global settings while testing
body: <p>i have a play 2.3 application that I want to test.
  This application has a Global.java class that extends GlobalSettings in order to start a recurring Akka task every 5minutes.</p>
  
  <p>During testing I don't want the task to be scheduled since it creates several issues and I don't need it.</p>
  
  <p>Therefore I would like to override the GlobalSettings.</p>
  
  <p>By reading the documentation, it looks like it should be possible to use a FakeApplication for that. However I tried to do that in several ways and the framework still runs my default global settings.</p>
  
  <p>I created a base class for my tests that looks like this:</p>
  
  <pre><code>public class BaseTest
    extends WithApplication
  {
    protected FakeApplication provideFakeApplication()
    {
      return fakeApplication(inMemoryDatabase("test"), new GlobalSettings());
    }
  }
  </code></pre>
  
  <p>According to the documentation, if a test class extends WithApplication a fake application should automatically start for me, with the configuration provided.
  Disregarding if this happens or not, even before the testing methods are called, the default global settings trigger. The "new Global()" doesn't override the default.</p>
  
  <p>I also tried to manually start the fakeApplication using a @BeforeClass annotation, with no success.</p>
  
  <p>I am running the tests with the "activator test" command.</p>
  
  <p>It looks like that the fakeApplication is indeed used for each test, but before even the first test starts, the main application is started and its global triggered. And that's what I don't want it to happen.</p>
  
  <p>Am I doing something wrong or is it a bug in play? if it is a bug, is there a workaround? </p>
  
  <p><strong>EDIT</strong>: I just noticed that even the database settings don't get overridden correctly. I normally use a h2 file database for developing, but i want a inmemory, different one for testing. However by using the code above doesn't change the database used, and therefore my tests run against my file DB.</p>
  
  <p>I also tried something like this:</p>
  
  <pre><code>  @Test
    public void testMyTest()
    {
      running(fakeApplication(inMemoryDatabase("test2")), () -&gt; {
        //TESTING CODE THAT USES DB
      });
    }
  </code></pre>
  
  <p>and still any query inside the body runs against the DB configured in the config file, not the inmemory database.</p>
  
  <p><strong>Edit</strong>
  Chafik solution kind of worked for me, since by specifying a different config file in the build.sbt file I managed to override my settings. Things are still really wierd though:
  1)Now if from my fakeApplication constructor I try to override the GlobalSettings by passing a new instance in helper method, the settings are correctly overridden, while before I could not at all override the main one
  2)If I revert my change and don't supply a test conf file, I can still override the globalsettings. That is, the behaviour is different than it used to be initially.</p>
  
  <p>Something is definitely strange around the test command, its configuration, running scope, and the way fakeApplication override the configuration, and/or the documentation about it si definitely unclear and lacking. However since at least I achieved what I wanted to do I'll still consider the answer solved.</p>