Posted in

How to disable Spring Rider in a test environment?

Hey everyone, quick heads up if you’re dealing with Spring Rider stuff in test environments – I’m on the vendor side of Spring Rider, so I see this question all the time from devs and QA teams who’re frustrated by the default Rider behavior popping up in staging or unit tests. Let’s break this down like I would over a coffee at a conference, no stuffy jargon, just real fixes that work. Spring Rider

First, let’s get clear: Spring Rider (for anyone new, that’s our component that auto-adjusts spring rates based on load, right? Perfect for real vehicles, but in tests? Total overkill. You don’t need it kicking in when you’re spinning up a mock car in a unit test, or running a regression suite on a test bench. The last thing you want is flaky tests because Rider is throwing unexpected rate changes when you’re testing brake response or cornering forces.

I’ve seen so many devs try to brute-force this – like, manually overriding every Rider instance in every test class – and that’s a nightmare. If we update our Rider code next quarter, your hardcoded overrides will break, and you’ll spend three weeks debugging why your tests are suddenly failing. Instead, let’s use the built-in test profiles we already have, because that’s how Spring is meant to work.

Wait, quick pro tip: If you’re using Spring Boot (which most of our clients do for their test infrastructure), make sure you’ve got test-specific properties set in src/test/resources/application-test.properties. That’s where all your test-specific config lives, no touching prod config here. For disabling Spring Rider, the first line you need there is spring.rider.enabled=false. Yeah, it’s that simple – our component has a built-in flag that checks for this property, so when it’s set to false, Rider stays completely dormant. No rate adjustments, no background processes, nada. It just acts like a regular static spring, which is exactly what you want for controlled tests.

But wait, what if you’re not using Spring Boot? A lot of our industrial clients use plain Spring with a DI container, no Boot. No problem – we still made it easy. Just add a @ConditionalOnProperty annotation on any Rider bean definition in your test config class, pointing to the spring.rider.enabled property. So something like @ConditionalOnProperty(name = "spring.rider.enabled", havingValue = "false", matchIfMissing = false). That way, Rider only exists in your test context if you explicitly tell it to, which it won’t if you’ve got the property set. No more extra beans cluttering up your test app context.

I know some of you are thinking, “What if I need Rider disabled only for specific test cases, not the whole suite?” Fair question. Let’s say you have 100 unit tests, but 5 of them specifically test Rider’s dynamic behavior. You don’t want to set spring.rider.enabled=false globally for all tests, because then those 5 tests will break. That’s where test annotations come in, not just profile properties. You can use @TestPropertySource to override the property for individual test classes or even methods. For example, if you have a test that verifies Rider increases rate when load goes up, you’d add @TestPropertySource(properties = "spring.rider.enabled=true") right above that test method. The rest of your tests stay disabled, and only the one test runs with Rider active. No more workarounds, no more skipping tests when Rider gets in the way.

Another thing I see mess people up: autowired Rider instances in test code. If you’re bringing a Rider bean into your test class without checking if it’s present, when you disable Rider, your tests will throw a NoSuchBeanDefinitionException. Duh, that makes sense – if it’s not in the context, you can’t autowire it. So the fix there is simple: use optional injection. In Java, that’s @Autowired(required = false) or @Resource(lookup = "rider", optional = true) – depending on your DI framework. That way, when Rider is disabled, the injection just returns null, and your test code can handle it gracefully. I’ve seen too many teams waste hours on this because they didn’t adjust their injection logic.

Wait, let’s talk about edge cases too. Some of our clients have custom Rider configurations that they use in prod, and they want to mirror that in tests – but still disable the dynamic adjustment. If you’re using a custom SpringRiderConfig bean in your prod setup, you don’t have to scrap that entirely for tests. Instead, just add rider.setDynamicAdjustmentEnabled(false) to your test config. That’s a method we expose on the Rider bean specifically for test use cases, so you can keep all your other custom settings (like spring preload, base rate) and just turn off the Rider’s dynamic feature. Way better than rebuilding a whole config from scratch.

I should also mention what happens when you disable Rider – it’s not a half-baked turn-off. We actually stop all background threads that handle rate adjustment, so there’s no leftover processes running in your test environment. That’s important because some test suites run hundreds of tests in parallel, and leftover threads can cause race conditions or memory leaks. I’ve had clients tell me this was a huge win for their test stability – before, they’d get random “thread not terminated” errors that they couldn’t trace, and now that’s gone completely.

Now, let’s cover a common mistake: mixing test profiles. A lot of devs will set spring.rider.enabled=false in application.properties instead of application-test.properties. That means it’ll be disabled even when you run your prod app, which is bad – Rider is essential there. Always make sure test-specific config is in the test resources folder, not the main one. It seems obvious, but I see this every single week.

Another gotcha: if you’re using a test framework like JUnit 5, make sure you’re not using a context that doesn’t pick up the test profile. For example, if you run a test with @SpringBootTest(classes = MyTestConfig.class), make sure MyTestConfig is loading the test profile, or that you explicitly set it with @ActiveProfiles("test"). Without that, the property won’t be applied, and Rider will still be running. It’s a tiny detail, but it trips up so many people.

Let’s wrap this up with a quick example, because code always helps. Suppose you have a unit test for a suspension control system. The test verifies that when a vehicle is loaded, the control system sends a signal to adjust the spring rate. If you disable Rider, that signal will never do anything – so your test will fail, which is actually the point. So to fix that, you’d do:

  1. In src/test/resources/application-test.properties: spring.rider.enabled=false
  2. Add @ActiveProfiles("test") to your test class
  3. For the specific test method that checks the rate adjustment signal, add @TestPropertySource(properties = "spring.rider.enabled=true")
  4. Use optional injection for Rider: @Autowired(required = false) private SpringRider springRider;

That’s it. No flaky tests, no weird errors, just your test running the way it should.

If you’re still having issues – maybe your setup is custom, or you’re running into something that’s not covered here – don’t hesitate to reach out. We build Spring Rider for teams like yours, so we’re happy to help tweak the config for your specific test infrastructure. Whether you need a custom test flag, or help integrating Rider with your test framework, our team’s here to walk through it with you. Contact us to discuss your needs today.

Unique Playground References
Spring Boot Test Documentation. https://spring.io/projects/spring-boot
Spring Framework Conditional Annotations. https://spring.io/docs
Spring Rider Test Configuration Guide. Vendor Internal Documentation, 2024.
JUnit 5 TestPropertySource API. https://junit.org/junit5/docs


Wenzhou Joyou Amusement Equipment Co., Ltd.
As one of the most professional spring rider manufacturers and suppliers in China, we’re featured by quality products and good price. Please rest assured to buy customized spring rider made in China here from our factory. Welcome to contact us for pricelist.
Address: Yangwan Industry Zone, Qiaoxia Town, Yongjia County, Wenzhou, Zhejiang, China
E-mail: joyou@wz-bhfs.com
WebSite: https://www.best-playground.com/