4
$\begingroup$

I'm teaching a capstone (the final class in an undergraduate program) software engineering course in which we are developing Android applications in Java. I consider test-driven development and unit testing important but am having trouble coming up with Android-related assignments, since so much mobile programming is about user interfaces and synchronization, neither of which are ideal for unit testing.

The only thing I've thought of is that they could unit test a database running on Android, which would also let me introduce mocking, but that doesn't sound very interesting.

Any suggestions of a small but interesting Android project suitable to TDD and unit testing?

$\endgroup$
3
  • $\begingroup$ Who is the course for?: What age? What level are they at? What experience? $\endgroup$ Feb 9, 2019 at 17:25
  • $\begingroup$ Capstone means it's the final class in a curriculum, an undergraduate program in this case. $\endgroup$ Feb 10, 2019 at 0:47
  • $\begingroup$ I'm not quite sure how an Android oriented codebase differs from the norm in regards to unit testing. Am I missing something? Isn't this just a matter of testing whatever business logic the code contains? $\endgroup$
    – Flater
    Feb 13, 2019 at 14:29

4 Answers 4

1
$\begingroup$

Tic tax toe.

Begin game. Test model state is:

 ---------

Move(x, 1, 1). Test model state is:

 ----x----

Scoring bowling.

Begin game. Test score is:

0

knock down 3 pins. Test score is:

3

Knock down 3 pins then 7 pins. Test score is:

13

Unit testing is orthogonal to android. Nothing about android keeps you from unit testing. You just have to insist on doing it. That means using a design that accommodates it.

$\endgroup$
2
$\begingroup$

I assume that there is some logic in the app, somewhere. Hard for me to imagine it otherwise.

If you build the client side with a Model-View-Controller architecture, the testing can be done on the model (as is most natural) and possibly on the controller.

If the server side is also built by the students, then it may also require logic beyond data access. So that can also be tested, either directly on the server side, or with mock clients. Maybe both.

I admit, though, that I don't build these things.

$\endgroup$
1
$\begingroup$

I have written a small game for Android, which I published on GitHub.

It's a board game, and I have written unit tests for all important parts of the program, especially for placing stones on the board. These tests are in the app/src/test folder.

Since I have translated the app into several languages, I have put the string messages into Android-style XML files. To test whether these string templates are filled with the correct placeholders, I had to test them in a more realistic environment. Therefore these had to go into the app/src/androidTest folder.

The code is already more than a year old and I'm still satisfied with it. Therefore I think it makes a good example.

$\endgroup$
1
$\begingroup$

As part of their coursework, my students build a master/detail application with a simple search field on the master page.

They have a testing assignment to write a JUnit functional test validating search-form input, as well as a Mockito test validating that search-form entries are correctly stored into / read from shared preferences.

You could go deeper w/ those two areas, and also assign UI tests that validate form rendering & correct passage to the detail activity.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.