Browse Source

添加和集成测试组件

jrison 6 years ago
parent
commit
6841240579

+ 2 - 0
lib_common/src/main/java/com/uas/module/common/base/BaseApplication.java

@@ -27,7 +27,9 @@ public class BaseApplication extends Application {
         super.onCreate();
         sInstance = this;
         Logger.init("pattern").logLevel(LogLevel.FULL);
+        Logger.d("BaseApplication onCreate()="+sInstance);
         Utils.init(this);
+        com.blankj.utilcode.util.Utils.init(this);
         mAppDelegateList = ClassUtils.getObjectsWithInterface(this, IApplicationDelegate.class, ROOT_PACKAGE);
         for (IApplicationDelegate delegate : mAppDelegateList) {
             delegate.onCreate();

+ 47 - 0
lib_common/src/main/java/com/uas/module/common/task/GlobalHandler.java

@@ -0,0 +1,47 @@
+package com.uas.module.common.task;
+
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+/**
+ * Created by Arison on 2019/3/27.
+ */
+public class GlobalHandler extends Handler {
+    
+    private HandleMsgListener listener;
+    private String Tag = GlobalHandler.class.getSimpleName();
+    
+    public interface HandleMsgListener{
+        void handleMsg(Message msg);
+    }
+
+    private static class Holder{
+        private static final GlobalHandler HANDLER = new GlobalHandler();
+    }
+
+    public static GlobalHandler getInstance(){
+        return Holder.HANDLER;
+    }
+
+
+    @Override
+    public void handleMessage(Message msg) {
+        if (getHandleMsgListener() != null){
+            getHandleMsgListener().handleMsg(msg);
+        }else {
+            Log.e(Tag,"请传入HandleMsgListener对象");
+        }
+        
+    }
+
+    public void setHandleMsgListener(HandleMsgListener listener){
+        this.listener = listener;
+    }
+
+    public HandleMsgListener getHandleMsgListener(){
+        return listener;
+    }
+
+
+}

+ 11 - 4
module_app/build.gradle

@@ -1,11 +1,7 @@
 apply plugin: 'com.android.application'
 
-// Create a variable called keystorePropertiesFile, and initialize it to your
-// keystore.properties file, in the rootProject folder.
 def keystorePropertiesFile = rootProject.file("keystore.properties")
-// Initialize a new Properties() object called keystoreProperties.
 def keystoreProperties = new Properties()
-// Load your keystore.properties file into the keystoreProperties object.
 keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
 
 static def buildTime() {
@@ -13,6 +9,16 @@ static def buildTime() {
 }
 
 android {
+
+    android.applicationVariants.all {
+        variant ->
+            variant.outputs.all {
+                //这里修改apk文件名
+                outputFileName = "${'uu'}_v${defaultConfig.versionName}_${buildType.name}.apk"
+            }
+    }
+ 
+    
     signingConfigs {
         release {
             keyAlias keystoreProperties['keyAlias']
@@ -80,5 +86,6 @@ dependencies {
         implementation project(':module_main')
         implementation project(':module_girls')
         implementation project(':module_news')
+        implementation project(':module_test')
     }
 }

+ 4 - 0
module_main/src/main/java/com/uas/module/main/MainActivity.java

@@ -22,6 +22,8 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
         findViewById(R.id.news_button).setOnClickListener(this);
         findViewById(R.id.girls_button).setOnClickListener(this);
         findViewById(R.id.fragment_button).setOnClickListener(this);
+        
+        findViewById(R.id.test_button).setOnClickListener(this);
     }
 
     @Override
@@ -34,6 +36,8 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
             ARouter.getInstance().build("/girls/list").navigation();
         } else if (view.getId() == R.id.fragment_button) {
             startActivity(new Intent(this, BottomNavigationActivity.class));
+        }  else if(view.getId()==R.id.test_button){
+            ARouter.getInstance().build("/test/index").navigation();
         }
     }
 

+ 6 - 0
module_main/src/main/res/layout/activity_main.xml

@@ -29,4 +29,10 @@
         android:layout_height="wrap_content"
         android:text="Fragment" />
 
+    <Button
+        android:id="@+id/test_button"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="Tests" />
+
 </LinearLayout>

+ 0 - 1
module_news/build.gradle

@@ -11,7 +11,6 @@ android {
         targetSdkVersion build_versions.target_sdk
         versionCode 1
         versionName "1.0"
-
         javaCompileOptions {
             annotationProcessorOptions {
                 arguments = [ moduleName : project.getName() ]

+ 1 - 7
module_news/src/main/java/com/uas/module/news/detail/NewsDetailActivity.java

@@ -5,13 +5,7 @@ import android.os.Bundle;
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.uas.module.common.base.BaseActivity;
 
-/**
- * <p>类说明</p>
- *
- * @author 张华洋 2017/7/1 13:13
- * @version V1.2.0
- * @name NewsDetailActivity
- */
+
 @Route(path = "/news/detail")
 public class NewsDetailActivity extends BaseActivity {
 

+ 2 - 1
module_news/src/main/java/debug/NewsApplication.java

@@ -1,12 +1,12 @@
 package debug;
 
+import com.orhanobut.logger.Logger;
 import com.uas.module.common.base.BaseApplication;
 import com.uas.module.common.http.DataType;
 import com.uas.module.common.http.HttpClient;
 import com.uas.module.common.http.OnResultListener;
 import com.uas.module.news.Constants;
 import com.uas.module.news.data.bean.StoryList;
-import com.orhanobut.logger.Logger;
 
 
 public class NewsApplication extends BaseApplication {
@@ -14,6 +14,7 @@ public class NewsApplication extends BaseApplication {
     @Override
     public void onCreate() {
         super.onCreate();
+        Logger.d("新闻组件初始...");
         login();
     }
 

+ 1 - 0
module_test/.gitignore

@@ -0,0 +1 @@
+/build

+ 57 - 0
module_test/build.gradle

@@ -0,0 +1,57 @@
+if (isModule.toBoolean()) {
+    apply plugin: 'com.android.application'
+} else {
+    apply plugin: 'com.android.library'
+}
+
+
+android {
+    compileSdkVersion build_versions.target_sdk
+//    buildToolsVersion "28.0.2"
+
+    defaultConfig {
+        minSdkVersion build_versions.min_sdk
+        targetSdkVersion build_versions.target_sdk
+        versionCode 1
+        versionName "1.0"
+        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+        javaCompileOptions {
+            annotationProcessorOptions {
+                arguments = [moduleName: project.getName()]
+            }
+        } 
+    }
+    
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+
+    sourceSets {
+        main {
+            if (isModule.toBoolean()) {
+                manifest.srcFile 'src/main/module/AndroidManifest.xml'
+            } else {
+                manifest.srcFile 'src/main/AndroidManifest.xml'
+                //集成开发模式下排除debug文件夹中的所有Java文件
+                java {
+                    exclude 'debug/**'
+                }
+            }
+        }
+    }
+    
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+    annotationProcessor deps.arouter_compiler
+    implementation project(':lib_common')
+compile 'com.android.support.constraint:constraint-layout:1.0.2'
+}

+ 25 - 0
module_test/proguard-rules.pro

@@ -0,0 +1,25 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in C:\Android\sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 26 - 0
module_test/src/androidTest/java/com/uas/module/test/ExampleInstrumentedTest.java

@@ -0,0 +1,26 @@
+package com.uas.module.test;
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumentation test, which will execute on an Android device.
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+    @Test
+    public void useAppContext() throws Exception {
+        // Context of the app under test.
+        Context appContext = InstrumentationRegistry.getTargetContext();
+
+        assertEquals("com.uas.module.test.test", appContext.getPackageName());
+    }
+}

+ 12 - 0
module_test/src/main/AndroidManifest.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.uas.module.test">
+
+    <application android:theme="@style/AppTheme">
+        <activity
+            android:name=".main.TestMainActivity"
+            android:label="@string/title_activity_test_main"
+            android:theme="@style/AppTheme"></activity>
+    </application>
+
+</manifest>

+ 32 - 0
module_test/src/main/java/com/uas/module/test/MyDelegate.java

@@ -0,0 +1,32 @@
+package com.uas.module.test;
+
+import com.blankj.utilcode.util.LogUtils;
+import com.uas.module.common.base.IApplicationDelegate;
+
+/**
+ * Created by Arison on 2019/3/27.
+ */
+
+public class MyDelegate implements IApplicationDelegate {
+    
+    @Override
+    public void onCreate() {
+
+        LogUtils.d("集成模式下 测试组件的初始化工作");
+    }
+
+    @Override
+    public void onTerminate() {
+
+    }
+
+    @Override
+    public void onLowMemory() {
+
+    }
+
+    @Override
+    public void onTrimMemory(int level) {
+
+    }
+}

+ 19 - 0
module_test/src/main/java/com/uas/module/test/main/TestMainActivity.java

@@ -0,0 +1,19 @@
+package com.uas.module.test.main;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+
+import com.alibaba.android.arouter.facade.annotation.Route;
+import com.uas.module.test.R;
+
+
+@Route(path = "/test/index")
+public class TestMainActivity extends AppCompatActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_test_main);
+    }
+
+}

+ 20 - 0
module_test/src/main/java/debug/LauncherActivity.java

@@ -0,0 +1,20 @@
+package debug;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+
+import com.uas.module.test.R;
+
+/**
+ * Created by Arison on 2019/3/27.
+ */
+
+public class LauncherActivity extends AppCompatActivity {
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_test_main);
+    }
+}

+ 15 - 0
module_test/src/main/java/debug/TestApplication.java

@@ -0,0 +1,15 @@
+package debug;
+
+import com.blankj.utilcode.util.LogUtils;
+import com.uas.module.common.base.BaseApplication;
+
+
+public class TestApplication extends BaseApplication {
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        //子组件的一些初始化工作
+        LogUtils.d("测试组件启动初始化...");
+    }
+}

+ 20 - 0
module_test/src/main/module/AndroidManifest.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.uas.module.test">
+    
+    <application
+        android:name="debug.TestApplication"
+        android:allowBackup="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/test_name"
+        android:supportsRtl="true"
+        android:theme="@style/AppTheme">
+       <activity android:name="debug.LauncherActivity">
+        <intent-filter>
+            <action android:name="android.intent.action.MAIN" />
+
+            <category android:name="android.intent.category.LAUNCHER" />
+        </intent-filter>
+    </activity>
+    </application>
+</manifest>

+ 9 - 0
module_test/src/main/res/layout/activity_test_main.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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"
+    tools:context="com.uas.module.test.main.TestMainActivity">
+
+</android.support.constraint.ConstraintLayout>

+ 4 - 0
module_test/src/main/res/values/strings.xml

@@ -0,0 +1,4 @@
+<resources>
+    <string name="test_name">module_test</string>
+    <string name="title_activity_test_main">TestMainActivity</string>
+</resources>

+ 17 - 0
module_test/src/test/java/com/uas/module/test/ExampleUnitTest.java

@@ -0,0 +1,17 @@
+package com.uas.module.test;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
+ */
+public class ExampleUnitTest {
+    @Test
+    public void addition_isCorrect() throws Exception {
+        assertEquals(4, 2 + 2);
+    }
+}

+ 1 - 1
settings.gradle

@@ -1,4 +1,4 @@
-include ':lib_common',
+include ':lib_common', ':module_test',
         ':module_app',
         ':module_main',
         ':module_girls',