2017-02-27 9 views
1

"Sonarqubeからのエラー: " 1ブランチカバレッジの最小しきい値に達するために、さらに1つのブランチをユニットテストでカバーする必要があります。私のユニットテストケースでは、条件が否定的であるためにカバーしていないからです。問題は、上記のif条件のための私のユニットテストケースで否定的なテストケースを生成する方法ですか?ユニットテスト

答えて

1

メソッドにkeeperstateを渡し、メソッドの外側から異なるkeeperstateを設定して、負のif条件をテストします。

public ZooKeeper connect(String connectionString, 
     String sessionTimeout, KeeperState keeperState) { 
     zookeeper = new ZooKeeper(connectionString,sessionTimeout, event -> { 
       if (event.getState() == keeperState) { 
        connectedSignal.countDown(); 
       } 
       } 
     ); 

     connectedSignal.await(this.sessionTimeout, TimeUnit.MILLISECONDS); 
    }