简体   繁体   中英

How to write groovy test for main class of Spring-boot application thast uses CommandLineRunner

My class is like:

@SpringBootApplication
class Test implements CommandLineRunner {
  public static void main(String[] args) {
    SpringApplication.run(Test.class, args);
  }

  @Override
  public void run(String... args) throws Exception {
    //some code
  }
}

How do I pass argument to run method? Currently written test as:

def "loads for class"() {
  expect:
  true
}

but it can't find the args for run method and fails.

If you use classic spring integration test, you can use:

@SpringBootTest(args = {"YOUR", "ARGS", "GO", "HERE"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM