我正在用Espresso编写UI测试.应用程序与服务器紧密配合,因此在很多情况下,我需要等待计算任一值,或者获取并显示数据等.Espresso建议使用IdlingResource.我的IdlingResource类看起来像这样(简单明了的例子).
public class IRViewVisible implements IdlingResource {
private View view;
private ResourceCallback callback;
public IRViewVisible(View view) {
this.view = view;
}
@Override
public String getName() {
return IRViewVisible.class.getName();
}
@Override
public boolean isIdleNow() {
if(view.getVisibility() == View.VISIBLE && callback != null) {
callback.onTransitionToIdle();
return true;
}
return false;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.callback = resourceCallback;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在任何地方都错了,请纠正我(因为有时在我看来我的IdlingResources无法正常工作).我setUp()像这样注册空闲资源:
IRViewVisible ir = new IRViewVisible(View v);
Espresso.registerIdlingResources(ir).
Run Code Online (Sandbox Code Playgroud)
在tearDown()上取消注册.
我找到了这篇文章(有一个名为"注册一个绑定到Activity实例的组件"的部分) - 我没有使用他的模式,但我检查了注册后(在每个方法中)设置为IdlingResource的视图的哈希码,并且它是不一样的观点 - 所有的哈希都是不同的.
另一个问题:一个Test类(它的结果)对另一个Test类没有任何影响,可以吗?
我想用 ConstraintLayout 做这个布局。
我所做的是添加 3 个 TextViews 1,2 和 3(粉红色)将它们连接到父级的左侧,并告诉它们在另一个之下。有用。
然后我需要添加视图 4 和 5,以便它们始终位于 2 和 3 的右侧,并且其内容必须垂直对齐到左边缘,如图所示。
当我添加时的问题
app:layout_constraintLeft_toRightOf="2 OR 3"
Run Code Online (Sandbox Code Playgroud)
4 和 5 中的文本未正确对齐。我明白了
当我使用指南时,我得到了这个
app:layout_constraintLeft_toRightOf="@id/guideline"
Run Code Online (Sandbox Code Playgroud)
有谁知道什么可以帮助解决这个问题?
编辑。第一次尝试的PS布局
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:id="@+id/constraintLayout"
>
<TextView
android:id="@+id/instrument_name"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="AUDUSD"
app:layout_constraintStart_toStartOf="@+id/constraintLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:id="@+id/trade_action_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="BUYjhkjhkjhvg"
app:layout_constraintStart_toStartOf="@+id/instrument_name"
app:layout_constraintTop_toBottomOf="@id/instrument_name"
tools:layout_editor_absoluteX="16dp"
android:layout_marginTop="1dp"/>
<TextView
android:id="@+id/net_pl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Net p/l"
app:layout_constraintStart_toStartOf="@+id/trade_action_label"
app:layout_constraintTop_toBottomOf="@id/trade_action_label"/>
<TextView
android:id="@+id/record_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
app:layout_constraintTop_toTopOf="@id/trade_action_label"
app:layout_constraintLeft_toRightOf="@id/trade_action_label"
tools:layout_editor_absoluteY="33dp"
/>
<TextView
android:id="@+id/pl_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12" …Run Code Online (Sandbox Code Playgroud) 在我的项目中,有3个类扩展了Thread,每个类都对整数进行了一些计算.我需要运行它们来获取所有三个计算值.需要对特定范围内的所有整数执行此过程.
这是我的一个主题:
public class FactorialNumber extends Thread {
private int number;
public void setNumber(int number) {
this.number = number;
}
public void run() {
try {
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print(NumbersOperations.getFactorial(number));
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个尝试启动线程的方法:
public static void getThreevalues() throws InterruptedException {
int startOfRange = getBorder("Enter the left border of range: ");
int endOfRange = getBorder("Enter the right border of range: ");
for(int i = startOfRange; i <= endOfRange; i++) {
PrimeNumber primeNumber = new PrimeNumber();
FibonachiNumber …Run Code Online (Sandbox Code Playgroud)