Integration Testing: Setting System Properties Before DeltaSpike : Adam Bien's Weblog

Integration Testing: Setting System Properties Before DeltaSpike : Adam Bien's Weblog Adam Bien's Weblog « Java EE 8 News,... | Main | Configuring The... » Integration Testing: Setting System Properties Before DeltaSpike DeltaSpike's Test-Control Module loads the unit test after the injected classes. Therefore any configured system properties set in @Before or even @BeforeClass are not going to be considered. To test the underlying class: public class SystemPropertyExposer { @Produces public String expose() { return System.getProperty("dev"); } } with e.g: @RunWith(PropertiesLoaderTestRunner.class) public class SystemPropertyExposerIT { @Inject String developer; @Test public void developerInjection() { assertThat(developer, is("duke")); } } You will have to set the property, before the initialization of SystemPropertyExposer. This can be achieved with the following workaround: import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; import org.junit.runners.model.InitializationError; public class PropertiesLoaderTestRunner extends CdiTestRunner { static { System.setProperty("dev", "duke"); } public PropertiesLoaderTestRunner(Class testClass) throws InitializationError { super(testClass); } } The sample above was pushed into: github.com/AdamBien/javaeetesting . See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly at Continuous Java EE 7 Testing and Quality . Posted at 03:56PM Jan 31, 2016 by Adam Bien , Comments[0]  | Views/Hits: 95 NEW workshop: HTML 5 and JavaScript Essentials , Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming. Newsletter: airhacks.news A book about rethinking Java EE Patterns Comments: Post a Comment: Name: E-Mail: URL: Notify me by email of new comments Remember Information? Your Comment: HTML Syntax: NOT allowed Number of posts: 1616 Number of comments: 5897 Yesterday's hits: 26006 Today's hits: 11486 Post reads / hour: 1382 Top posts: Adam Bien 236357 Java 8: Reading A File Into A String : Adam Bien's Weblog 70581 Adam Bien's Weblog 61059 Java 7+: Writing A String To File--A One Liner : Adam Bien's Weblog 45567 Simplest Possible EJB 3.1 / REST (JSR-311) Component : Adam Bien's Weblog 22963 Client-Side HTTP Basic Access Authentication With JAX-RS 2.0 : Adam Bien's [...] 20618 Don't use JPA's RESOURCE_LOCAL on the server : Adam Bien's Weblog 16193 Trending (last hour): Java 8 FlatMap Example : Adam Bien's Weblog 15 Java 8: From a for-loop to forEach statement : Adam Bien's Weblog 13 Java 8: Reading A File Into A String : Adam Bien's Weblog 11 EJB 3 Persistence (JPA) For Absolute Beginners - Or Create Read Update Dele[...] 7 Java 8: Streaming A String : Adam Bien's Weblog 5 about.adam-bien.com blog archives realworldpatterns.com Real World Java EE Patterns Rethinking Best Practices Order from amazon.de Order from amazon.com Online Workshops ...the last 150 posts Pushing Full Profile Java EE Applications To Amazon EC2 Container Service 20+ Topics in 45 mins -- 35th airhacks.tv Questions and Answers JPA and Microservices, RxJava, CRUD and TX, Gradle, Cross Field Validation, Licensing, MDA or Topics For The 35th airhacks.tv JSON Is The New Data Transfer Object (DTO) Asynchronous WAR To WAR Communication With WebSockets Creating A CustomElement (WebComponent) From Scratch 60k eBills per Hour, Tiny WARs -- Or Java EE 7 In Mass Billing and Public Services Market in Slovenia Launching Java EE Thin WARs In The Clouds Upcoming Cloud, Microservice, Web and Java EE Events Importance of Java EE, JCP, Java EE Guardians and Microprofile--Interview With Reza Rahman Java 8 Base64 Encoding / Decoding Java 8 partitioningBy Example Java 8 groupingBy Example Java Is #1 In January 2017 Spring Boot vs. Wordpress, SOAP Rocks, CDI CMT, Reactive vs. Blocking IO, or 34th airhacks.tv is available 2017 Predictions Java EE vs. Spring, State of Microprofile, Is SOAP nice? Oracle targets non-payers or the topics for the 1.2017 / 34th airhacks.tv My Blog is a Personal Notepad Java 8: Converting An Array To A Stream Scalable, Productive, Decoupled, Resilient and Hacky New 2017! How To Maximize Fun In Enterprise Projects URL Templates With JAX-RS GlassFish on Steroids, Micro, Full, Clouds and Commercial Support--An Interview With Dominika Tasarz Load Balancing Microservices With Docker, nginx and TomEE Accidental Spring Evangelism, Rolling Updates, Log Management, Exception Factories, Docker, Queuing Choices or 33rd airhacks.tv Java EE 8 News, Central Logs, Layering, Util, ExceptionFactories, JDBC in Docker, DTOs, Lombok--Or 33rd airhacks.tv TomEE 7.0.2 Full--Docker Smoke Test Slicing The Monolith--With Java EE And Docker HTTP Status Code Test Service: statustest Custom Matchers, Better Messages: JAX-RS Client Rulz v0.0.4 released New Java EE Related Docker Images Arrived: Docklands Adding And Substracting Path Instan