java - 如何比较同一方法的两个变量值
问题描述
同一类有两种方法。我想通过使用断言来比较两个变量的值。
这是两种方法
//方法一
public void Edit_window() throws InterruptedException {
collection_title.clear();
// driver.wait(2000);
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
collection_title.sendKeys(dateFormat.format(date));
}
//方法二
public void name_collection()
{
String updated_title=col_title.getText() ;
System.out.println("the title eof the collectio is " + updated_title) ;
System.out.println("the value is" + date) ;
}
因此,如果您可以看到有一个变量“日期”,它包含当前日期。我想要该变量值并与方法 2 中定义的变量值“updated_title”进行比较。请输入任何内容!
解决方案
您基本上可以将方法的返回类型更改为字符串类型,然后添加断言。下面的示例:
public String Edit_window() throws InterruptedException {
collection_title.clear();
// driver.wait(2000);
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = new Date();
collection_title.sendKeys(dateFormat.format(date));
return dateFormat.format(date);
}
public String name_collection()
{
String updated_title=col_title.getText() ;
System.out.println("the title eof the collectio is " + updated_title) ;
System.out.println("the value is" + date) ;
return date;
}
//然后对于断言你基本上可以:Assert.asserEquals(classObject.Edit_window(), classObject.name_collection);
推荐阅读
- python - 为什么我们在 python 中使用多态性和抽象类
- python-3.x - Python Pandas:如何插入一个新列,该列是另一列的下一个“n”(也可以是分数)值的总和?
- angular - *ngIf 没有按预期隐藏/显示组件
- apache-arrow - Arrow Streaming 是端到端无拷贝的吗
- c++ - AES/CTR 解密使用 Crypto++ 意外停止?
- react-hooks - 钩子回调中来自 useState 的变量被关闭
- python-3.x - 使用Python将新值插入SortedLinked List?
- java - 如何在另一个 LinkedList 的末尾分配一个 LinkedList 的一部分?
- r - 长到宽格式聚合 R tidyverse
- python - 如何在python中将字节转换为字符