English 中文(简体)
• 如何撰写瓜瓦率单位测试
原标题:How to write unit test for Guava rate Limiter applied on a methods

I am trying to write unit test for RateLimiter using guava.

下面是我的服务班级,我在那里增加了Limiter。 我想对参加服务班的许可证发放方法。 我将胶片/薄膜定为3。

任何人都能够帮助我进行单位测试,以检查从事或不从事工作的比率。

  1. any single method
  2. multiple methods
@Service
class Service{ 
 private  RateLimiter rateLimiter;

  @Autowired
  public void setRateLimiter(RateLimiter rateLimiter) {
    this.rateLimiter = rateLimiter;
  }

public method1(){

rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();

}

public method2(){

rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();

}

public method3(){

rateLimiter.acquire();
System.out.println(new Date() + ": Beep");
xyzMethod();

}

}

@Configuration
public class RatelimiterConfig {

  @Value("${tps}")
  private int tps;

  @Bean
  public RateLimiter rateLimiter(){
    return  RateLimiter.create(tps);
  }
}

问题回答

暂无回答




相关问题
Speed up compilation with mockito on Android

I am currently developing an android app in eclipse using: One project for the app One project for the tests (Instrumentation and Pojo tests) In the test project, I am importing the mockito library ...

Injecting Mockito mocks into a Spring bean

I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the @Autowired annotation on ...

What to do when Java Best Practices conflict with Mockito

My development team has started to use Mockito and have classes that have been defined as final . I ve read in Effective Java by Joshua Bloch and in the SO thread When to use final that all classes ...

Java: Mock testing probably with Mockito

I think I m not using verify correctly. Here is the test: @Mock GameMaster mockGM; Player pWithMock; @Before public void setUpPlayer() throws SecurityException, NoSuchFieldException, ...

热门标签