Spring profiles on integration tests class -
we have selenium tests ran java test class.
on local environment ok, want switch off tests when run on jenkins.
so use:
@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = application.class) @webintegrationtest("server.port=1234") @profile("!jenkins") @activeprofiles("integrationtests") public class loginandeditprofileseleniumtest { ...
what works: running mvn clean test
run tests locally, integrationtests
profile active. dont want pass additional parameter.
what want achieve: running mvn clean test -dspring.profiles.active=jenkins
switch off test.
can merge somehow profile passed parameter, activeprofile annotation , take profile annotation consideration? :)
//update: possible use class extending activeprofilesresolver:
public class activeprofileresolver implements activeprofilesresolver { @override public string[] resolve(class<?> testclass) { final string profilefromconsole = system.getproperty("spring.profiles.active"); list<string> activeprofiles = new arraylist<>(); activeprofiles.add("integrationtests"); if("jenkins".contains(profilefromconsole)){ activeprofiles.add("jenkins"); } return activeprofiles.toarray(new string[activeprofiles.size()]); } }
but seems not cooperate @profile anyway ( jenkins profile active test still running ) .
@profile
has zero affect on test classes. thus, should remove annotation.
if want enable test class if given system property present specific value, use @ifprofilevalue
.
however, in scenario, want disable test class if given system property present specific value (i.e., if spring.profiles.active
contains jenkins
).
instead of implementing custom activeprofileresolver
, more elegant solution use junit assumption cause entire test class ignored if assumption fails.
this should work nicely you:
import static org.junit.assume.*; // ... @beforeclass public static void disabletestsonciserver() { string profilesfromconsole = system.getproperty("spring.profiles.active", ""); assumefalse(profilesfromconsole.contains("jenkins")); }
regards,
sam (author of spring testcontext framework)
Comments
Post a Comment