0

私は現在、それぞれテスト付きの2つの関数を持っています。

function A(x) {
  // do A things
  return Aresults;
}
function testA() {
  // this put A through its test and make sure it does what it's supposed to
}

function B(x) {
  // do B things which involve using A
  return Bresults;
}
function testB() {
  // this put B through its test and make sure it does what it's supposed to
}

私は今、Aの唯一の使用法がBであることに気づきました。そこで、コードを分離して保護するためにリファクタリングしたいと思います。

function B(x) {
  function A(x) {
    // do A things
    return Aresults;
  }
  // do B things which involve using A
  return Bresults;
}
function testB() {
  // this put B through its test and make sure it does what it's supposed to
}

私の質問は、AがBのクローズドオーバー関数になったので、どうすればAのテストを追加できるかということです。つまり、私のtestA関数はどこに行きますか?

4

1 に答える 1

0

あなたはする必要はありません。単体テストの目的は、実装ではなく動作をテストすることです。

したがって、どのように実行するかではなく、どのメソッドが実行するかをテストします。

この観点からは、関数呼び出しによって生成される副作用のみに注意する必要があります。それだけです。

于 2013-03-14T03:21:47.020 に答える