简体   繁体   English

如何为opengl es2.0 android app编写junit测试

[英]how to writing junit test for opengl es2.0 android app

i was new to this android testing. 我是这个Android测试的新手。 What i want is to write a junit(with Mockito) test for my fragment which is a GLSurfaceView with one Custom GLRenderer. 我想要的是为我的片段编写一个junit(带有Mockito)测试,它是带有一个Custom GLRenderer的GLSurfaceView。

public class SuefaceViewFragment extends Fragment{

private View mRootView;

private GLSurfaceView mSurfaceView;
private CustomRenderer mRenderer;


public SurfaceViewFragment() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_surface_view, container, false);
    initView();
    return mRootView;
}


private void initView() {
    mSurfaceView = (GLSurfaceView) mRootView.findViewById(R.id.surface_view);

    mSurfaceView .setRenderer(mRenderer);
    mSurfaceView .setZOrderMediaOverlay(true);        
    mSurfaceView .setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}


@Override
public void onResume() {
    super.onResume();
    mSurfaceView.onResume();
}

@Override
public void onPause() {
    super.onPause();
    mSurfaceView.onPause();
}

} }

this is the GLSurfaceView 这是GLSurfaceView

public class CustomRenderer implements GLSurfaceView.Renderer {




public CustomRenderer() {

}



private void init() {

    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    init();
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

}

@Override
public void onDrawFrame(GL10 gl) {

    render();
}

private void render() {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);

   // To Do Rendering code

}

I want to write unit testing for this above fragment using using Junit and Mockito. 我想使用Junit和Mockito为上述片段编写单元测试。 is it possible? 可能吗? if possible how to write? 如果可能怎么写?

unit tests test your business logic. 单元测试可以测试您的业务逻辑。 they specifically do not work with anything involving the android sdk (include fragments) 它们特别不适用于涉及android sdk的任何内容(包括片段)

Testing GLSurfaceView is not possible by any of the android test frameworks. 任何Android测试框架均无法测试GLSurfaceView。 UiAutomator and Espresso both need a view to test on (a button to click for example) and the reason why open gl is so fast is partly because it doesn't belong in a view tree. UiAutomator和Espresso都需要一个视图进行测试(例如单击一个按钮),而open gl这么快的部分原因是它不属于视图树。 the only "view" android knows about is the GLSurfaceView. android唯一知道的“视图”是GLSurfaceView。

You might be able to just record touch events and replay them via adb send touch events to interact with the app. 也许可以只记录触摸事件并通过adb send touch事件重播它们以与应用程序进行交互。 it will work, but it is brittle. 它可以工作,但是很脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM