Skip to content

@Scheduled annotation does not work in test if bean is annotated with @SpyBean #8489

Closed
@dome313

Description

@dome313

The Spring boot configuration I'm using is

@SpringBootApplication
@EnableScheduling
public class Application {
  public static void main(final String[] args) { SpringApplication.run(Application.class, args);}
}

In configuration there's a bean

@Component
public class MyBeanWithScheduledAnnotation {
  @Scheduled(fixedRateString = '#{fixedRate}')
  public void myJob() {
    ....
  }
}

If I use this bean with @SpyBean in my SpringBootTest, the scheduled job does not execute. The test code looks like this:

@RunWith(SpringRunner.class)
@SpringBootTest
public class Test

@SpyBean
MyBeanWithScheduledAnnotation bean
...

pom.xml contains only two dependencies spring-boot-starter-web and spring-boot-starter-test

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions