Font Size: a A A

Research On Android JNI Code Unit Test Methods

Posted on:2016-01-14Degree:MasterType:Thesis
Country:ChinaCandidate:H YuFull Text:PDF
GTID:2308330461469088Subject:Computer technology
Abstract/Summary:PDF Full Text Request
With the widespread use of the Android operating system, more and more Android apps appear in our lives. A considerable number of apps have been developed by mixed using Java and C/C++. The JNI code is an intermediary between Java code and C/C++ code. It is necessary to test the JNI code because JNI code is very important and error-prone. In this paper, we focus on JNI code unit test methods and the corresponding test tools construction.This paper first introduces Android JNI principles in detail. Then, based on the JNI principles, various common JNI code errors are analyzed and some solutions for avoiding the errors are addressed. Finally, this paper mainly studied on two kinds of JNI code testing methods:the static testing method and the dynamic testing method.For static testing method, this paper provides a list of common JNI code errors and a list of JNI programming optimization methods, and proposes two methods:code reviewing and static scanning. Code reviewing is a common manual testing method. In this method, the errors are found by reading the JNI code source file and comparing to the common JNI code error list and the JNI programming optimization list. Static scanning is an automated test method, which utilize jnichecker to scan the JNI code file to find the errors in the code. This paper introduces the detailed design and implementation for jnichecker, discusses the realization algorithm for file pre-processing and error detecting.For dynamic testing method, this paper introduces how to use gtest and gmock to test C/C++ code in the state-based and interaction-based ways, analyzes and points out that JNI code mainly depends on JNIEnv and JavaVM interfaces. The three kinds of methods that separately using real object, stub and mock object instead of the dependent interface to test JNI code are discussed. This paper proposes a mock-based method to test the JNI code. This method invokes the jnimock to create the mock objects which can cooperate with gtest and gmock to effectively test the JNI code. In this paper, the detailed design and realization methods of jnichecker are introduced. The jnichecker project has been open-sourced on GitHub. The tester can use jnimock API to write JNI code test cases.
Keywords/Search Tags:JNI code test, static testing, jnichecker, dynamic testing, jnimock
PDF Full Text Request
Related items