Monday, May 25, 2009

 

I have been a good developer and deserve a cookie

...for I have spent the last couple of hours building Android JUnit test cases.

See my very first post to see how to run these kinds of tests. It's kinda cool; after triggering 'em from the command line, you can flip to the Android emulator, and see the windows and text appearing and disappearing...

A few interesting points here, anyways:



Feast thine eyes:


package com.rezendi.wtw.test;

import android.content.Intent;
import android.database.Cursor;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.widget.Button;
import android.widget.EditText;

import com.rezendi.wtw.R;
import com.rezendi.wtw.Settings;
import com.rezendi.wtw.TravelNoteEdit;
import com.rezendi.wtw.TravelNotesDbAdapter;

/**
* Test code for a travel-note lifecycle.
*
* @author Jon Evans
*
*/
public class NoteTest extends ActivityInstrumentationTestCase2 {

public NoteTest() {
super("com.rezendi.wtw", TravelNoteEdit.class);
}

/* (non-Javadoc)
* @see android.test.AndroidTestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}

/* (non-Javadoc)
* @see android.test.AndroidTestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}

/**
* Open an empty TravelNoteEdit and check all is well.
*/
public void test1EmptyNote() {
TravelNoteEdit tne = (TravelNoteEdit) getActivity();

EditText titleEdit = (EditText) tne.findViewById(R.id.title);
String titleText = titleEdit.getText().toString();
assertEquals(0, titleText.length());

EditText bodyEdit = (EditText) tne.findViewById(R.id.body);
String bodyText = bodyEdit.getText().toString();
assertEquals(0, bodyText.length());

Button picButton = (Button) tne.findViewById(R.id.addPicture);
assertEquals(picButton.getText(), tne.getText(R.string.addPicture));
}

/**
* Open TravelNoteEdit, edit its contents, save its data, check saved data, delete.
*/
@UiThreadTest
public void test2DataSave() {
TravelNoteEdit tne = (TravelNoteEdit) getActivity();

tne.setLocationString("wtwTest"); // mark this as test data
EditText titleEdit = (EditText) tne.findViewById(R.id.title);
titleEdit.setText(titleEdit.getText().toString()+ "test edited");

EditText bodyEdit = (EditText) tne.findViewById(R.id.body);
bodyEdit.setText(bodyEdit.getText().toString()+ "test edited");

Button saveButton = (Button) tne.findViewById(R.id.save);
saveButton.performClick();

//OK, we're done, so;
TravelNotesDbAdapter dbAdapter = new TravelNotesDbAdapter(getInstrumentation().getTargetContext());
dbAdapter.open();
Cursor note = dbAdapter.fetchTestNotes();
String newTitleText = note.getString(
note.getColumnIndexOrThrow(TravelNotesDbAdapter.KEY_TITLE));
String newBodyText = note.getString(
note.getColumnIndexOrThrow(TravelNotesDbAdapter.KEY_BODY));
note.close();

assertEquals("test edited", newTitleText);
assertEquals("test edited", newBodyText);

dbAdapter.deleteTestData();
dbAdapter.close();
}

/**
* Create a note in the database, open TravelNoteEdit, check its contents.
*/
public void test3DataLoad() {
TravelNotesDbAdapter dbAdapter = new TravelNotesDbAdapter(getInstrumentation().getTargetContext());
dbAdapter.open();
long testId = dbAdapter.createNote(Settings.KEY_TEST, "test title", "test body", "test picture");

Intent intent = new Intent(getInstrumentation().getTargetContext(), TravelNoteEdit.class);
intent.putExtra(TravelNotesDbAdapter.KEY_ROWID, testId);
this.setActivityIntent(intent);

TravelNoteEdit tne = (TravelNoteEdit) getActivity();

EditText titleEdit = (EditText) tne.findViewById(R.id.title);
String titleText = titleEdit.getText().toString();
assertEquals("test title", titleText);

EditText bodyEdit = (EditText) tne.findViewById(R.id.body);
String bodyText = bodyEdit.getText().toString();
assertEquals("test body", bodyText);

Button picButton = (Button) tne.findViewById(R.id.addPicture);
assertEquals(picButton.getText(), tne.getText(R.string.seePicture));

dbAdapter.deleteTestData();
dbAdapter.close();
}
}

Labels: , , , ,


Comments:
Look who it is! “Why should you do my paper? What are some of the things I can expect when you do my assignment?” It would help if you had an idea of what you will get when you pay someone online to write your task. Once you hire https://essaysrescue.com/masterpapers-review/ for a term, thesis, or essay paper, you can expect writing that has the following characteristics.
 
Thanks for this amazing blog this is too much informative.
 
Thanks
 
This is great to hear about a website development company that has a good developer. It's important to find someone who is experienced and knowledgeable in web development so that your website can be a success. It's also great to know that the company is reliable and trustworthy. Thanks for sharing!
 
I'm so glad to hear that you've been a good developer! Hard work definitely deserves recognition. A cookie sounds like the perfect way to reward yourself - enjoy!
 
"Sweet Rewards: Celebrating Your Hard Work as a Developer" is a gentle reminder to honor your achievements and embrace self-recognition in your professional journey. As a developer, you've earned the right to celebrate your dedication and hard work, and a simple cookie is a delightful way to do so.
attorney for bankruptcy near me
 
Your insights about being a good developer really resonate with me. It’s all about finding balance and consistency, not just in coding but in life too. Speaking of consistency, I recently started taking Cinnamon Gummies
as part of my daily routine to help maintain steady energy levels and focus. It’s funny how small habits, like taking these gummies, can make a big difference in productivity and well-being. Has anyone else here tried them or found similar ways to stay on top of their game?
 

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]