Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass properties to maven profile while running tests in intellij

I have a maven pom with profiles. In one of those profiles I refer to a system variable like this

<profile>
    <id>kasper</id>
    <properties>
        <user>${username}</user>
    </properties>
</profile>

When I invoke maven command line with the -Dusername=kasper all seems to be well.

The thing is, I import this project in IntelliJ. IntelliJ 13 allows to select profiles with which to run, through the Maven Tool Window.

When I select this specific profile to use while running tests, I can't seem to find how to replace this property correctly, i.e. to really tell IntelliJ that it has to pick this or that user name to run my maven tests, I tried a bit of everything and it doesn't seem to pick ot up.

Anybody an idea?

Kasper

like image 704
Kasper Avatar asked Apr 01 '14 15:04

Kasper


3 Answers

In IntelliJ 14 maven profiles are not passed to tests (by default).

You can activate this mechanism via an option in Settings -> Maven -> Running Tests which let you enable passing of systemPropertyVariables to unit tests - this should cover your case.

like image 69
PaoloC Avatar answered Oct 15 '22 17:10

PaoloC


View -> Tool Windows -> Maven Projects then right clicking on needed phase, e.g. package it will be second item in context menu called *Create [project_name] package ...*

And on some tabs you could override VM properties, add profiles, etc.

like image 24
Mysterion Avatar answered Oct 15 '22 19:10

Mysterion


OK, I got it.

Go to the Intellij configuration on JUnit or TestNG (whichever one you are using). Under VMoptions... you can add the custom system property variables from Maven to debugger beside -ea option just like terminal command.

-ea -Dtest.environment=QA

like image 31
Mikey Avatar answered Oct 15 '22 17:10

Mikey