0

I am looking to instantiate a spring boot test in code.

I have a set of cucumber test, which instantiate my app’s spring context using @SpringBootTest, but I am now looking to leverage the same tests and steps code, but to run against my deployed app.

So I am looking to:

  • check a system property
  • instantiate a my local context in a SpringBootTest environment if system property set
  • instantiate a different SpringBootTest context which hits a live instance of my service.

Does anybody have any recommendations on how to do that?

P.S.

I use spring boot for my service, junit4 and maven.

ren
  • 115
  • 3
  • 14
  • dont know where is your deployed app, but if it is in a ecosystem that have maven, you could refer to this question answers : https://stackoverflow.com/questions/12238149/how-to-configure-pom-to-run-tests-packaged-in-a-jar – Mohammed Housseyn Taleb Jun 10 '19 at 00:15
  • This useful guide : https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html – 0gam Jun 10 '19 at 01:29
  • @MohammedHousseynTaleb when I say deployed I mean a live running instance of my app in a docker container - it could be running anywhere it could also not be a java app at all! – ren Jun 10 '19 at 05:55

1 Answers1

0

Ovarall, all Junit test setting still working in spring boot.

  1. you can use below methods for your setting/configuration before overall testing

    @BeforeClass public static void setUpClass() { System.out.println("@BeforeClass setUpClass"); myExpensiveManagedResource = new ExpensiveManagedResource(); }

    @AfterClass public static void tearDownClass() throws IOException { System.out.println("@AfterClass tearDownClass"); myExpensiveManagedResource.close(); myExpensiveManagedResource = null; }

  2. you can also do configuration for each method

    @Before public void setUp() { this.println("@Before setUp"); this.myManagedResource = new ManagedResource(); }

    @After public void tearDown() throws IOException { this.println("@After tearDown"); this.myManagedResource.close(); this.myManagedResource = null; this.println(" "); }

  • my goal is not to instantiate my context at all, because that will require to open up ports, connects to databases, kafka etc. – ren Jun 10 '19 at 05:52
  • If I understand your question correctly, you can ingest your live instance of service in the @BeforeClass method. – Charlie_li2005 Jun 10 '19 at 11:49