0

I am using @HystrixCommand as follows in a my method

@HystrixCommand(fallbackMethod = "fallbackCircuit", groupKey = "group-key", commandProperties = {
            @HystrixProperty(name = "requestCache.enabled", value = "true"),
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")})

 public void someMethod(String input){
 ...
 }


 public void fallbackCircuit(String input, Throwable e){
 ...
 }

But I am not able to test the fallback method? The fallback method is not called in my tests. I think I have not setup the tests properly. What would be a better way of testing fallback method?

2 Answers2

0

Although not directly testing the fallback method, another question I've answered has a solution that shows the circuit breaker is triggered. See How can I unit-test javanica @HystrixCommand annotated methods? if you're interested.

Ciaran George
  • 571
  • 5
  • 19
0

There is no need to test the @HystrixCommand() if you want to test the fallback method in your UT's you can directly call your fallback method in your unit tests and assert on its response/result.