小编Erc*_*rch的帖子

在ABAP单元测试中模拟sy-uname

我正在尝试用ABAP编写我的第一个单元测试。

我的测试方法(通过system variable sy-uname)获取登录用户的团队成员。

因为我希望测试能够为所有人运行,所以我不能只让方法运行并声明我自己的团队成员之一。

我要模拟sy-uname,所以测试不依赖于执行它的人。

这可能吗?如果是,您如何模拟系统参数?

sap abap unit-testing mocking

4
推荐指数
1
解决办法
172
查看次数

为什么要在类中声明变量,甚至在构造函数中将该变量赋值给它

在下面的代码中,您可以看到我constObjTest类中声明了一个变量.并同时在构造函数中分配constObj对象this.

为什么我们需要再次声明变量,即使我们已经this在构造函数中将其赋值?

webstormIDE,它抛出的错误doesn't have the property constObj,如果我这样做this.constObj,如果变量没有声明.但代码工作正常没有问题.

声明变量是强制性的,即使我们将其赋值给 this

const constObj = {
  a: function() {
    console.log("sivakumar");
  }
};

class Test {
  constObj: any; // Is this line mandatory? I mean declaring it???

  constructor() {
    Object.assign(this, {
      constObj
    });
  }

  callMethod() {
    this.constObj.a();
  }
}

new Test().callMethod();
Run Code Online (Sandbox Code Playgroud)

如果我们不申报,请告知,将会发生什么.

javascript typescript

3
推荐指数
1
解决办法
43
查看次数

标签 统计

abap ×1

javascript ×1

mocking ×1

sap ×1

typescript ×1

unit-testing ×1