On 5 February 2010 10:01, Martin Höller <mar...@xss.co.at> wrote:

> Am Freitag, 5. Februar 2010 09:50:04 schrieb Søren Krogh Neigaard:
> > Im getting grey hairs :)
> >
> > I tried with this in my pom.xml:
> >
> > <plugin>
> >   <groupId>org.apache.maven.plugins</groupId>
> >   <artifactId>maven-surefire-plugin</artifactId>
> >   <version>2.5</version>
> >   <configuration>
> >     <systemPropertyVariables>
> >       <db.driver>oracle.jdbc.OracleDriver</db.driver>
> >       <db.url>${database.url}</db.url>
> >       <db.username>${database.username}</db.username>
> >       <db.password>${database.password}</db.password>
> >     </systemPropertyVariables>
> >   </configuration>
> > </plugin>
>
> That's almost exactly how I do it. The differences are:
> - I'm still using surefire 2.4.2
> - Due to the older version I use the (now) deprecated method of defining
>  system properties in surefire (<systemProperties> instead of
>  <systemPropertyVariables>)
>
> How and where are you trying to access the properties? In some JUnit test
> which is executed by the maven surefire plugin via
> System.getProperty("db.url")? That definitely works for me.
>
> However, Stephen's comments about locking you to maven this way sounds
> reasonable. His approach is probably the better one. But I don't know yet
> how
> these properties could be used in pom.xml for plugin configuration. Do they
> get imported by maven somehow?
>

My way would have test.properties with the following contents:

db.driver=oracle.jdbc.OracleDriver
db.url=${database.url}
db.username=${database.username}
db.password=${database.password}

By having the test resource filtered, the properties from the pom/settings
will be substituted into the resource when it is copied to
target/test-classes by maven-resources-plugin

If you decide to move away from maven, all you have to do is modify how the
test.properties file gets copied...

and the bonus is that you can debug the property substitution as you can
look at target/test-classes/test.properties to verify that it is being
substituted correctly.


>
> hth,
> - martin
>

Reply via email to