Android Test Tutorial: TestCase sample

Source: Internet
Author: User
Tags array length assert

The Android test framework is based on JUnit, so some classes that are not related to the platform can be tested directly using the testcase in JUnit.

Morsecodeconvertertest is used to test morsecodeconverter classes, Morsecodeconverter implementations are not connected to the Android platform, so you can use testcase directly as a base class.

TestCase is derived from the Assert class, Assert provides a large number of assert methods to compare expected and actual values.

This example code is as follows:

public class Morsecodeconvertertest extends TestCase {     

 @SmallTest public 
 void Testcharacters () throws Exception {     

 long[] expectedbeeps = {     
 Morsecodeconverter.dot,     
 Morsecodeconverter.dot,     
 Morsecodeconverter.dot ,     
 Morsecodeconverter.dot,     
 Morsecodeconverter.dot};     
 long[] beeps = Morsecodeconverter.pattern (' s ');     

 Assertarraysequal (expectedbeeps, beeps);     
 }     

 private void Assertarraysequal (long[] expected, long[] actual) {     
 assertequals ("unexpected array length.",     
 Expected.length, actual.length);     
 for (int i = 0; i < expected.length i++) {     
 long expectedlong = expected[i];     
 Long Actuallong = Actual[i];     
 Assertequals ("Unexpected Long at index:" + I,     
 expectedlong, Actuallong);}}     

For a basic JUnit Testcase test, use assertequals to test expected and actual values.

See a full set of tutorials: http://www.bianceng.cn/OS/extra/201301/35252.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.