Q:

how to override Spring Boot autowired component during testing

I'm trying to write tests for a Spring Boot batch application.
I have an interface "WsaaClient" and two implementations, I need to use one of them for normal execution and the other for testing purposes.
In the project, I have FCEClient class that has an autowired field "LoginManager", which has an autowired field "WsaaClient".
@Component
@Profile("!dev")
public class FCEClient implements IFCEClient {

  @Autowired
  LoginManager loginManager;

@Component
public class LoginManager {

  @Autowired
  WsaaClient client;

@Component
public class AfipWsaaClientSpring extends AfipWsaaClient {

AfipWsaaClient is in a non-spring maven dependency. It implements WsaaClient.
Running the Spring Batch application works well and AfipWsaaClientSpring is picked.
Now I want to write a test and need to use a dummy implementation for WsaaClient.
So I put under src/test/java this class:
@Component
public class TestWsaaClientSpring  implements WsaaClient {

And this test:
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class FceBatchApplicationTests {

  private JobLauncherTestUtils jobLauncherTestUtils;

  @Test
  public void testJob() throws Exception {

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    Assert.assertEquals("COMPLETED", jobExecution.getExitStatus().getExitCode());
  }
}

Running it from JUnit Launcher on Eclipse throws:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'afipWsaaClientSpring' defined in file [/home/guish/vmshare/eclipsews/ec/ec-batch/target/classes/com/mycompany/AfipWsaaClientSpring.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mycompany.AfipWsaaClientSpring]: Constructor threw exception; nested exception is java.io.FileNotFoundException: ./wsaa_client.properties (No such file or directory)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1303) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]

The FileNotFoundException is not relevant, the file is not present because of running as a test and Spring Boot should not pick the AfipWsaaClientSpring implementation.
How can I override the Autowired option in my test code and choose TestWsaaClientSpring instead?
And just in case, how can I prevent Spring Boot from instantiating the AfipWsaaClientSpring when running as a test?

A:

Annotation @SpringBootTest has 'properties' attribute (https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/SpringBootTest.html).
so, you can specify spring profile like this,
@SpringBootTest(properties = {"spring.profiles.active=test"}, classes=MyConfiguration.class)

