Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide spring boot banner.txt in junit test with SpringJUnit4TestRunner?

When I configure an Spring Boot Application, I can disable the banner via run configuration in the static main method. So far so good.

But what if I have the following:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={MyApplication.class})
public class MyApplicationTest { 
  ....
}

When I run this test, it does not use the static main method and the banner is displayed, making it harder to focus on the relevant logging statements.

Is there a switch or config annotation I can use to simulate new SpringApplication(MayApplicationclass).setShowBanner(false)...?

like image 403
Jan Galinski Avatar asked Jan 24 '26 02:01

Jan Galinski


2 Answers

You can put this in your test properties:

spring.main.show_banner=false
like image 144
Tomas Avatar answered Jan 25 '26 16:01

Tomas


You can specify the property in your test annotation:

@SpringBootTest(properties="spring.main.banner-mode=off")
like image 26
Adrian Baker Avatar answered Jan 25 '26 15:01

Adrian Baker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!