MongoDB
 SQL >> Datenbank >  >> NoSQL >> MongoDB

Zusätzliche Konfiguration in Play-2-FakeApplication-Tests laden

Für Play-Integrationstests können Sie eine weitere Konfigurationsdatei laden und deren Properties in eine Fake-Anwendung übergeben.

private Configuration additionalConfigurations; @Before public void initialize() { Config additionalConfig = ConfigFactory.parseFile(new File("conf/integration.conf")); additionalConfigurations = new Configuration(additionalConfig); } @Test public void testPropertiesGetLoaded() throws Exception { running( testServer(3333, fakeApplication(additionalConfigurations.asMap())), HTMLUNIT, new Callback<TestBrowser>() { public void invoke(TestBrowser browser) { String specificProperty = Play.application().configuration().getString("specific.property"); System.out.println(specificProperty); } } ); }

Das erspart das manuelle Zusammensetzen großer Property-Maps und hält Testkonfiguration und Produktivkonfiguration sauber getrennt.