Skip to content

Commit

Permalink
First version for open source
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochuang committed Sep 12, 2016
1 parent b73995e commit 9148f69
Show file tree
Hide file tree
Showing 47 changed files with 1,816 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# OSX
.DS_Store

# android generated
bin/
gen/

# eclipse
.classpath
.settings
.project

local.properties
project.properties

# IDEA
.idea/
*.iml
out/

# gradle
build/
.gradle/
gradlew.bat

# build
lint.xml
lint.html
proguard-rules.txt

#local gradle configurations
local.gradle

.gradletasknamecache
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

## 这个project是怎么来的?

蘑菇街目前采用组件化的开发方式,一个app由很多个模块组成,每个模块都有单元测试的部分,然而有很多代码都是类似的。因此,为了减少重复劳动,我们花时间抽出来一个独立的project,专门做unit testing用的。

## 这个project是干什么用的?

如前所述,这个project里面主要是一些unit testing会用到的公共代码,来帮助你更快的做unit testing,减少一些boilerplate code。
说白了就是一些帮助类,里面有些帮助方法。
比如里面有个TestBase,里面有

```
// <=> 是等效于的意思
ae() => Assert.assertEquals()
at() => Assert.assertTrue()
af() => Assert.assertFalse()
```

目前还没有完整的文档,要看都有哪些帮助类,哪些方法可以看源码哦,目前总共也没几个。
总之,有了这个project,单元测试将变得更加的简单。

## 这个project用到那些框架/技术?
JUnit4, Robolectric,Mockito,AssertJ,Gson
如果你不懂什么叫unit test,额。。。
如果你不懂JUnit的使用,额。。。
如果你不懂Mockito的使用,请看[这里](http://www.vogella.com/tutorials/Mockito/article.html)
如果你不懂Robolectric的使用,请看[这里](http://mitx.mobile.mogujie.org/topic/191/%E7%94%A8robolectric-%E5%9C%A8local-jvm%E4%B8%8A%E8%B7%91android-unit-test)


## 怎么样使用?
目前你可以使用http://jitpack.io/来引入这个项目

## 一些小例子

```java
public class StringUtils {
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
}

//测试纯Java代码,继承TestBase
public class StringUtilsTest extends TestBase {

@Test
public void should_isEmpty_works() {
at(StringUtils.isEmpty(null)); //at() is short for Assert.assertTrue()
at(StringUtils.isEmpty(""));
af(StringUtils.isEmpty(" ")); //af() is short for Assert.assertFalse()
af(StringUtils.isEmpty("hello"));
}

}

//测试Android相关的代码,继承RobolectricTestBase,同时需要指定constants = BuildConfig.class,不然的话,会报资源找不到的错误
@Config( constants = BuildConfig.class )
public class ColorUtilsTest extends RobolectricTestBase {
@Test
public void should_parseColor_valid_color() {
ae(Color.RED, Color.parseColor("#FF0000"));
ae(Color.WHITE, Color.parseColor("#FFFFFF"));
}
}
```

欢迎各种PR,建议以及吐槽!
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.application'
repositories {
jcenter()
}

android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.mogujie.natasha"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
testCompile project(':lib')
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/xiaochuang/Library/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 *;
#}
13 changes: 13 additions & 0 deletions app/src/androidTest/java/com/mogujie/natasha/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mogujie.natasha;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.mogujie.natasha"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
13 changes: 13 additions & 0 deletions app/src/main/java/com/mogujie/natasha/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mogujie.natasha;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mogujie.natasha.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</RelativeLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/values-w820dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">natasha</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
15 changes: 15 additions & 0 deletions app/src/test/java/com/mogujie/natasha/ExampleUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mogujie.natasha;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
25 changes: 25 additions & 0 deletions app/src/test/java/com/mogujie/natasha/MainActivityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mogujie.natasha;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

/**
* Created by xiaochuang on 4/22/16.
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class MainActivityTest extends ActivityTestBase<MainActivity> {

@Test
@JSpec(desc = "should activity not null")
public void testactivitynotnull() {
ann(getActivity());
}

@Override
protected Class<MainActivity> activityClass() {
return MainActivity.class;
}
}
8 changes: 8 additions & 0 deletions app/src/test/java/com/mogujie/natasha/TestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mogujie.natasha;

/**
* Created by xiaochuang on 4/22/16.
*/
public class TestTest extends TestBase {

}
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Sep 01 17:59:00 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Loading

0 comments on commit 9148f69

Please sign in to comment.