fun add() {
return 4+1;
}
class Calculator {
fun MathUtils() {
// do something
// calls add() function
val x: Int = add()
// return something
return x + 22
}
}
class CalculatorTest {
var c = Calculator()
@Test
fun MathUtilsSuccess() {
Assertions.assertThat(
c.MathUtils()
).isEqualTo(24)
}
}
Run Code Online (Sandbox Code Playgroud)
我是单元测试的新手,我想知道有什么方法可以调用MathUtils()函数(在计算器类中)
在MathUtilsSuccess()(CalculatorTest类内)中,我必须模拟add()不在任何类内的函数,以便add()始终返回2,以便在成功的情况下我的测试通过。
所有类都在单独的文件中,有趣的 add() 也在单独的文件中。
PS:我已将我的疑问分解为这个简单的示例,这不是我正在解决的实际问题。
在 C++ 编程中,我将字符串作为指针传递
代码:
#include<iostream>
using namespace std;
void changeString(string *s) {
// change s[1] to 'a' inside this function
}
int main(void) {
string s = "ayush";
changeString(&s);
cout<<s;
}
Run Code Online (Sandbox Code Playgroud)
我写了代码 *s[1] = 'a',但它显示错误。我如何访问函数“changeString”中字符串的第一个字符。请帮助我们感谢任何支持。