我正在编写Spring Unit测试代码。单元测试@Before方法没有被执行。因为它直接运行@PostConstruct我得到了erorrs,Caused by: java.lang.IllegalArgumentException: rate must be positive
因为默认值是0.00。我想设置一些值来请求最大限制,以便postcontstruct块顺利通过。我的代码有什么问题?请帮忙。
@Componentpublic class SurveyPublisher { @Autowired private SurveyProperties surveyProperties; @PostConstruct public void init() { rateLimiter = RateLimiter.create(psurveyProperties.getRequestMaxLimit()); } } public void publish() { rateLimiter.acquire(); // do something }}
//单元测试类
public class SurveyPublisherTest extends AbstractTestNGSpringContextTests { @Mock SurveyProperties surveyProperties; @BeforeMethod public void init() { Mockito.when(surveyProperties.getRequestMaxLimit()).thenReturn(40.00); } @Test public void testPublish_noResponse() { //do some test }}
ITMISS
相关分类