`

android junit入门(五)@SmallTest@MediumTest@LargeTest

 
阅读更多
原文http://googletesting.blogspot.jp/2010/12/test-sizes.html
引用

by Simon Stewart

What do you call a test that tests your application through its UI? An end-to-end test? A functional test? A system test? A selenium test? I’ve heard all them, and more. I reckon you have too. Tests running against less of the stack? The same equally frustrating inconsistency. Just what, exactly, is an integration test? A unit test? How do we name these things?

Gah!

It can be hard to persuade your own team to settle on a shared understanding of what each name actually means. The challenge increases when you encounter people from another team or project who are using different terms than you. More (less?) amusingly, you and that other team may be using the same term for different test types. “Oh! That kind of integration test?” Two teams separated by a common jargon.

Double gah!

The problem with naming test types is that the names tend to rely on a shared understanding of what a particular phrase means. That leaves plenty of room for fuzzy definitions and confusion. There has to be a better way. Personally, I like what we do here at Google and I thought I’d share that with you.

Googlers like to make decisions based on data, rather than just relying on gut instinct or something that can’t be measured and assessed. Over time we’ve come to agree on a set of data-driven naming conventions for our tests. We call them “Small”, “Medium” and “Large” tests. They differ like so:
Feature Small Medium Large
Network access No localhost only Yes
Database No Yes Yes
File system access No Yes Yes
Use external systems No Discouraged Yes
Multiple threads No Yes Yes
Sleep statements No Yes Yes
System properties No Yes Yes
Time limit (seconds) 60 300 900+

Going into the pros and cons of each type of test is a whole other blog entry, but it should be obvious that each type of test fulfills a specific role. It should also be obvious that this doesn’t cover every possible type of test that might be run, but it certainly covers most of the major types that a project will run.

A Small test equates neatly to a unit test, a Large test to an end-to-end or system test and a Medium test to tests that ensure that two tiers in an application can communicate properly (often called an integration test).

The major advantage that these test definitions have is that it’s possible to get the tests to police these limits. For example, in Java it’s easy to install a security manager for use with a test suite (perhaps using @BeforeClass) that is configured for a particular test size and disallows certain activities. Because we use a simple Java annotation to indicate the size of the test (with no annotation meaning it’s a Small test as that’s the common case), it’s a breeze to collect all the tests of a particular size into a test suite.

We place other constraints, which are harder to define, around the tests. These include a requirement that tests can be run in any order (they frequently are!) which in turn means that tests need high isolation --- you can’t rely on some other test leaving data behind. That’s sometimes inconvenient, but it makes it significantly easier to run our tests in parallel. The end result: we can build test suites easily, and run them consistently and as as fast as possible.

Not “gah!” at all.

  • 大小: 17.2 KB
分享到:
评论

相关推荐

    对JUnit的一点简单讲解包括一点简单的Android JUnit的讲解

    例如,`@UiThreadTest`注解用于表示该测试必须在主线程运行,而`@SmallTest`, `@MediumTest`, 和 `@LargeTest` 分别代表不同的测试规模。 文件列表中的`runnerdemo.tar.gz`和`junit_demo1.tar.gz`可能包含了示例...

    Android下使用JUnitTest用例

    在Android开发中,JUnitTest是进行单元测试的重要工具,它基于Java的JUnit框架,使得开发者能够在Android环境中对代码进行验证和测试。本文将详细介绍如何在Android项目中设置和使用JUnitTest用例,以及如何通过...

    Junit_test.rar_JUnit_JUnit测试_junit工具 @test

    这个名为"Junit_test.rar"的压缩包显然包含了一个关于JUnit的示例程序,旨在帮助学习者更好地理解和应用JUnit进行测试。 在Java开发中,单元测试是对代码的最小可测试单元进行验证的过程,例如单个方法。JUnit提供...

    android-junit单元测试(附代码)

    import androidx.test.ext.junit.runners.AndroidJUnit4; @RunWith(AndroidJUnit4.class) public class MainActivityTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule...

    Android JUnit单元测试实例

    一个简单的Android JUnit测试类通常会继承自`androidx.test.ext.junit.runners.AndroidJUnit4`。这个运行器使得我们可以在Android环境中使用JUnit 4的特性。例如: ```java import androidx.test.ext.junit.runners...

    android-junit5,使用junit 5进行android测试。.zip

    `android-junit5`插件提供了一个`test`任务,可以覆盖默认的`testDebugUnitTest`任务: ```groovy apply plugin: 'de.mannodermaus.android-junit5' android { // ... } tasks.test { useJUnitPlatform() } ```...

    在JUnit中使用@Rule测试文件和目录Java开发Ja

    JUnit作为Java领域最流行的测试框架,提供了丰富的功能来帮助开发者编写高效、可靠的测试用例。在本文中,我们将深入探讨如何在JUnit中利用`@Rule`注解来测试文件和目录,从而提升测试的覆盖率和实用性。 `@Rule`是...

    Android Junit使用

    测试类需要继承`androidx.test.ext.junit.runners.AndroidJUnit4`,并使用`@Test`注解标记测试方法。例如: ```java import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; public class...

    Junit 5中@ParameterizedTest与@EnumSource结合使用

    在Java的单元测试框架JUnit 5中,`@ParameterizedTest` 和 `@EnumSource` 是两种非常实用的注解,它们可以有效地提高测试代码的复用性和覆盖率。`@ParameterizedTest` 允许我们将测试方法参数化,也就是说,同一个...

    android cts介绍,及junit测试

    在Android开发中,JUnit结合了Android Testing Support Library,提供了一些专门为Android环境设计的测试工具,如`@UiThreadTest`用于在UI线程上运行的测试,`@SmallTest`, `@MediumTest`, `@LargeTest`用于标记不同...

    android junit.rar

    AndroidJUnit是Android平台上进行单元测试的关键工具,它基于Java的JUnit框架,允许开发者对应用程序的代码进行自动化测试。在Android开发中,单元测试是确保代码质量、可维护性和避免引入bug的重要环节。本资料详细...

    android junit4

    要开始使用JUnit4进行Android测试,你需要创建一个测试类,这个类通常会放在项目的`src/test/java`目录下,并且需要继承`androidx.test.ext.junit.runners.AndroidJUnit4`。这个测试类中的方法会被识别为测试用例,...

    Java单元测试JUnit4.7

    1. **注解(Annotations)**:JUnit 4.7的一大亮点就是使用注解(@Test, @Before, @After等)来标记测试方法、设置初始化和清理操作。这使得测试类的结构更清晰,代码更易读。 2. **参数化测试**:允许用不同的参数...

    android Junit

    androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' ``` 这样,你就可以在Android Studio中编写和运行JUnit测试了。 2. **...

    解决java junit单元测试@Test报错的问题

    1. **缺少JUnit库**:如果项目中没有正确地导入JUnit相关的jar包,那么编译器无法识别@Test注解,导致测试无法执行。你需要确保项目构建路径中包含了JUnit的库文件,通常是`junit-4.x.jar`或更高版本。 2. **JUnit...

    Android Studio中Junit调试

    ### Android Studio中的JUnit调试 #### 一、JUnit简介 JUnit是一种用于Java编程语言的单元测试框架,它最初由Kent Beck和Erich Gamma开发,并作为XUnit家族的一员而广为人知。JUnit的设计目的是为了帮助开发者编写...

    JUnit入门及简单使用

    JUnit3的测试类需要遵循特定的命名规则,比如测试方法必须以`test`作为前缀。而JUnit4引入了注解(annotation)机制,极大地简化了测试代码,使得编写和执行测试更加方便。使用JUnit4时,需要注意你的JDK版本应为1.5...

Global site tag (gtag.js) - Google Analytics