GithubHelp home page GithubHelp logo

yingfengchen / natasha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meili/natasha

0.0 2.0 0.0 99 KB

蘑菇街开源的安卓单元测试框架

Home Page: https://github.com/mogujie/natasha

License: MIT License

Java 100.00%

natasha's Introduction

这个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的使用,请看这里
如果你不懂Robolectric的使用,请看这里
有任何单元测试的问题,请看这里

怎么样使用?

目前你可以使用http://jitpack.io/来引入这个项目

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    compile 'com.github.mogujie:natasha:v0.1.1'
}

一些小例子

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,建议以及吐槽!

natasha's People

Contributors

chriszou avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.