我正在尝试运行这样的单元测试:
@org.junit.jupiter.api.Test
void junit5codeCoverage() {
final int result = new Foo().junit5();
Assert.assertEquals(Looper.getMainLooper().getThread(), Thread.currentThread());
assertEquals(-1, result);
}
Run Code Online (Sandbox Code Playgroud)
这是一个带有 Android 依赖项(即)和 Robolectric的Junit5测试Looper.getMainLooper()
。
我正在使用mannodermaus 的 junit5 android 插件,它允许在 Android 设置中运行 junit5。但这不是开箱即用的,因为它不会加载 robolectric。所以我尝试了alixwar 的分支,它可以解决 robolectric 和 junit5 测试覆盖率,但仍然不会使用 Android 类。
此外,我还开始研究如何在 junit5 上运行 robolectric 测试,这需要了解其RobolectricTestRunner
工作原理以及如何将代码移植到 JUnit5 平台。我对新的 junit5 平台知之甚少,但我发现我可以在运行器之上构建org.junit.platform.runner.JUnitPlatform
,以遵循测试运行器概念,这是junit-platform-runner
包的一部分。但这与最初的 Junit4 相去甚远,SandBoxTestRunner
以至于我无法完成移植。
那么,实现 robolectric junit5 支持的最可行路径是什么,或者我缺少任何(明显的)概念?
在使用LayoutInflater对Fragment中的布局进行膨胀时,我收到此异常:
./res/layout/locations_list.xml line #-1 (sorry, not yet implemented): Error inflating class com.costum.android.widget.LoadMoreListView
Run Code Online (Sandbox Code Playgroud)
我发现在充气自定义布局时会发生这种情况
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.locations_list, container, false);
}
Run Code Online (Sandbox Code Playgroud)
编辑这是locations_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<com.costum.android.widget.LoadMoreListView
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
任何其他布局充气机工作,如在此测试中:
@Test
public void testInflator() {
ActivityController<SherlockFragmentActivity> activityController = CustomTestRunner
.startActivity();
SherlockFragmentActivity activity = activityController.get();
LayoutInflater from = LayoutInflater.from(activity);
View view = from
.inflate(com.twisper.R.layout.locations_list_item, null);
assertNotNull(view);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用带有2.2-SNAPSHOT的Robolectric,现在我的问题是如何解决这个问题或者如何实现缺少的功能,robolectric文档非常稀疏,因此我很难找到任何起点.
全栈跟踪
android.view.InflateException: XML file ./res/layout/locations_list.xml …
Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法来完成xsd架构到数据存储区往返,只需要很少的努力.
我使用jaxb从模式构建我的对象模型,现在我想基于JPA(或JDO或其他东西?)存储这些对象.是否可以使用基于JAXB注释的缺失注释自动增强对象?这是可取的吗?
谢谢
有没有办法报告Bugs,类似于Android反馈客户端,但没有在市场上注册我的应用程序.我仍在研究应用程序,有些用户正在对它进行alpha测试,因此接收报告/堆栈跟踪会很有用.是否有通用的方法或应用程序?
如何删除(剪切)纹理中的透明矩形,以使孔透明.
在Android上我会使用Xfermodes方法:
但是在libgdx中我将不得不使用opengl.到目前为止,我几乎达到了我想要的,通过使用glBlendFunc从这个非常有用且非常有用的页面我得知
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
Run Code Online (Sandbox Code Playgroud)
应该解决我的问题,但我尝试了,它没有按预期工作:
batch.end();
batch.begin();
//Draw the background
super.draw(batch, x, y, width, height);
batch.setBlendFunction(GL20.GL_ZERO,
GL20.GL_ONE_MINUS_SRC_ALPHA);
//draw the mask
mask.draw(batch, x + innerButtonTable.getX(), y
+ innerButtonTable.getY(), innerButtonTable.getWidth(),
innerButtonTable.getHeight());
batch.end();
batch.setBlendFunction(GL20.GL_SRC_ALPHA,
GL20.GL_ONE_MINUS_SRC_ALPHA);
batch.begin();
Run Code Online (Sandbox Code Playgroud)
它只是使面具区域变成黑色,而我期待透明度,任何想法.
这就是我得到的:
这是我的预期:
如何使用 adb shell 在 Android 上访问时钟速度 (CLK_TCK)。在 ubuntu 上这很容易:
$ getconf CLK_TCK
Run Code Online (Sandbox Code Playgroud) 我想比较一个数据类的多个实例之间的值,以便我知道哪个值发生了变化:
data class A(val name : String)
val firstA = A("hello")
val secondA = A("you")
if (secondA.name.changed(firstA)) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式访问的属性函数.name
并在另一个目标值上执行它(在这个例子中是 firstA)而不显式定义它吗?代表可以在这里提供帮助,或者我如何在有和没有反思的情况下解决这个问题?
我试图反序列化一个相当复杂的POJO JSON,我需要在其中定义一个特定的属性名称来进行类型解析,但是找不到这个相当简单的功能.
假设一个类如下:
class Example {
int id;
Map<String,Object> extras;
}
Run Code Online (Sandbox Code Playgroud)
和Jackson正确地将POJO序列化为JSON,其中地图被序列化为键值映射,就像预期的那样:
{...
id:5,
extras:{object1:{...}, object2:{...}}
...}
Run Code Online (Sandbox Code Playgroud)
现在我想告诉杰克逊根据实际类型明确地反序列化附加对象.所以我需要告诉Jackson以某种方式将"object1"映射到Type A,将"object2"映射到B型.
这可能吗?谢谢.
使用Espresso,我尝试使用Home按钮测试将活动发送到后台,然后再次将其放到前台进行一些检查:
@EspressoTest
public void test() {
onSomeView().check(matches(isDisplayed()));
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);
Context context = getInstrumentation().getTargetContext();
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
onSomeView().check(matches(isDisplayed()));
}
Run Code Online (Sandbox Code Playgroud)
我不得不使用intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
异常建议的,但除此之外我还测试了,启动它作为Launcher Activity,或使用
FLAG_ACTIVITY_REORDER_TO_FRONT
,但视图不可见.即使测试通过.
我在onCreate中启动了一个警告对话框,允许用户从两个不同的活动中进行选择.我使用了具有正值和负值的警告对话框但不幸的是我收到了错误.是否无法使用此类警报对话框来运行两种不同的活动?如果是的话怎么可能?我遇到这种错误:
[Android Application]
[Android Application]
[Android Application]
[Android Application]
[Android Application]
[Android Application]
[Android Application]
[Android Application]
DalvikVM [localhost:8602]
Thread [<1> main] (Running)
Thread [<10> Binder_2] (Running)
Thread [<9> Binder_1] (Running)
Thread [<11> Thread-198] (Suspended (exception RuntimeException))
<VM does not provide monitor information>
Handler.<init>(Handler$Callback, boolean) line: 200
Handler.<init>() line: 114
AlertDialog(Dialog).<init>(Context, int, boolean) line: 109
AlertDialog.<init>(Context, int, boolean) line: 114
AlertDialog$Builder.create() line: 931
MainActivity$splashscreen.run() line: 68
[Android Application]
Run Code Online (Sandbox Code Playgroud)
这是我的警告对话框的代码
public class MainActivity extends Activity {
//ImageView image;
@Override
protected void …
Run Code Online (Sandbox Code Playgroud)