Angularjs 测试非常简单的角度控制器是否有意义?

Angularjs 测试非常简单的角度控制器是否有意义?,angularjs,testing,Angularjs,Testing,这是我们的一个控制器。正如您所看到的,这是一个非常简单的控制器 angular. module("printing"). controller("PrintController", function PrintController( $window, localize, PartsEnum, IsBitIncluded ) { "use strict"; this.PartsEnum = ExamPartsEnum; this.IsBit

这是我们的一个控制器。正如您所看到的,这是一个非常简单的控制器

angular.
module("printing").
controller("PrintController", function PrintController(
    $window,
    localize,
    PartsEnum,
    IsBitIncluded
) {
    "use strict";

    this.PartsEnum = ExamPartsEnum;
    this.IsBitIncluded = IsBitIncluded;

    this.origin = $window.location.protocol + "//" + $window.location.host;

    this.optionsText = [
        localize.get("Yes"),
        localize.get("Maybe"),
        localize.get("No"),
    ];
});
  • 我们应该为此控制器编写测试吗?如果你需要更多的信息来回答这个问题,那么写下的信息会左右你的答案
  • 关于这个控制器,我们应该测试什么?它几乎什么也不做。有什么需要测试的

老实说,我不会写一个测试来测试这个控制器的逻辑,因为正如你所说的,它做的很少。我要测试的是检查您的源url格式是否正确,以及范围上是否存在“是”、“可能”、“或”选项。这样,当将来有人修改某些内容时,他将知道在运行测试时他破坏了某些内容

所以基本上可以归结为:

  • 测试您编写的功能
  • 在未来测试修改并提供安全网

  • 为了完整性/代码覆盖率,我还声明设置了其他两个属性。