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

<p>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. </p>

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

CC BY-SA 4.0
2019-03-17T02:00:43.263Z
2019-03-17T02:00:43.263Z
Brendenw
<p>I have written a <a href="https://senseis.xmp.net?PhantomGo" rel="nofollow noreferrer">small game for Android</a>, which I published <a href="https://github.com/rillig/Phantom-Go-Android" rel="nofollow noreferrer">on GitHub</a>.</p>

<p>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 <code>app/src/test</code> folder.</p>

<p>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 <code>app/src/androidTest</code> folder.</p>

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

CC BY-SA 4.0
2019-02-14T13:54:44.380Z
2019-02-14T13:54:44.380Z
Roland Illig
<p><strong>Tic tax toe.</strong> </p>

<p>Begin game. Test model state is:</p>

<p>&nbsp;---------</p>

<p>Move(x, 1, 1). Test model state is:</p>

<p>&nbsp;----x----</p>

<p><strong>Scoring bowling.</strong></p>

<p>Begin game. Test score is:</p>

<p>0</p>

<p>knock down 3 pins. Test score is:</p>

<p>3</p>

<p>Knock down 3 pins then 7 pins. Test score is:</p>

<p>13</p>

<p>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. </p>

CC BY-SA 4.0
2019-02-10T11:42:13.897Z
2019-02-10T20:34:49.057Z
2019-02-10T20:34:49.057Z
candied_orange
<p>I assume that there is <em>some</em> logic in the app, somewhere. Hard for me to imagine it otherwise. </p>

<p>If you build the client side with a <a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow noreferrer">Model-View-Controller</a> architecture, the testing can be done on the model (as is most natural) and possibly on the controller. </p>

<p>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. </p>

<p>I admit, though, that I don't build these things. </p>

CC BY-SA 4.0
2019-02-09T12:00:54.573Z
2019-02-11T14:36:28.357Z
2019-02-11T14:36:28.357Z
Buffy
<p>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.</p>

<p>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.</p>

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

CC BY-SA 4.0
2019-02-09T17:25:24.177Z
Who is the course for?: What age? What level are they at? What experience?
ctrl-alt-delor
CC BY-SA 4.0
2019-02-10T00:47:31.197Z
Capstone means it's the final class in a curriculum, an undergraduate program in this case.
Ellen Spertus
CC BY-SA 4.0
2019-02-13T14:29:21.157Z
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?
Flater
<labs><unit-testing>
What's a good unit testing assignment for Android?
# What's a good unit testing assignment for Android?

(Asked by: username_0 on 2019-02-09)

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?

**Tags:** labs, unit-testing

> **Comments:**
> **username_1**: Who is the course for?: What age? What level are they at? What experience?  
> **username_0**: Capstone means it's the final class in a curriculum, an undergraduate program in this case.  
> **username_2**: 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?  

---

## 4 answers

### Answer by username_5 on 2019-02-10. Score: 1 | Accepted answer

**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.


---

### Answer by username_6 on 2019-02-09. Score: 2

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](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) 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.


---

### Answer by username_3 on 2019-03-17. Score: 1

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.


---

### Answer by username_4 on 2019-02-14. Score: 1

I have written a [small game for Android](https://senseis.xmp.net?PhantomGo), which I published [on GitHub](https://github.com/rillig/Phantom-Go-Android).

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.


---

