Reputation: 63
I have a test suite that test my web service, I want to sent a custom IP as a CLI argument from maven to the test suite so instead of having a hard-coded IP like in the example below:
@Before
public void server_connection() {
ConnectionToServer serverConnection = new ConnectionToServer("localhost", 5776);
serverConnection.open();
}
I want to have a variable IP like this:
@Before
public void server_connection() {
ConnectionToServer serverConnection = new ConnectionToServer(IPArgumentFromMaven, 5776);
serverConnection.open();
}
Upvotes: 1
Views: 2283
Reputation: 145
In your method, you can read this value as a system property like this:
@Before
public void server_connection() {
ConnectionToServer serverConnection = new ConnectionToServer(System.getProperty("IPArgumentFromMaven"), 5776);
serverConnection.open();
}
Now you can pass a value for IPArgumentFromMaven to maven from command line like this:
mvn clean test -DIPArgumentFromMaven=localhost
Upvotes: 2