15 February 2013

How to make simple game in Android part 7. - Testing

WARNING!
Few honest informations.  
I have a few years experience in software developer BUT  I am NOT a game developer! I am NOT an expert. 
This guide was written by person who want write game as part of hobby and make dreams come to true (As i want to write simple RPG game in future).   
 I put best efforts to write  accuracy informations, but I cannot guarantee the perfect accuracy of all content in this  articles  on this blog.
I do not take any responsibility or liability for any error, omission , inaccuracy
or destructions!

How to make simple game in Android


BASED ON GAME EXAMPLE: 
DOMS COUNTRIES, CAPITOLS, FLAGS AND CONTINENTS QUIZ GAME

 TO DOWNLOAD GAME

Part 7 
TESTING

I will be honest. I didn't write any JUnit tests and I haven't done proper test. Shame on me!

I didn't see too much sense for write  tests for quick project with extreme time constraint like 'writing small application in weekend'. I believe in this type of cases writing a tests can be a too much hassle and it was a too much hassle for me. 

I wrote some test for my applications that tests core functionality, but I am not TDD-fanatic (TDD stands for Test Driven Development, and it is a software development process, where you write a test, before you even write code to meet its purpose. If want know more read quite cool article http://www.agiledata.org/essays/tdd.html).
I am not good in writing test for android application as I have problem with find and write a meaningful tests. (I am aware, that is my weakness I need to improve this).

I don't write simple test case like for sets/gets methods and other obvious basics as I believe is waste of time, but I assume that TDD-fanatic will don't agree with that. Depends on your software development methodology and styles, You should decide.. .How many test you planning to write.
Specially in games is useful to have debug mode, where you can test how game behave in specific situation.

So what I should test in 'doms countries capitals and flags quiz game'?
Here you can find my ideas for test:


High scores where you can test:
  •  place and scores are correct.
  • Is sorting for scores works  
  • (TDD people will test add and remove score)


In Level You can test:
  •  is level 4 unique answer,
  • is 50 questions are unique


Countries:

  • you can test is loading file loaded all
  • is data is correct
  • amount of countries is correct

As you can see my code is not well written as is hard to test many method are void (doesn't have return value).Make sure,that when you writing 
 I have done 2 types of 'sort of' tests:
I validate date in load countries from file and load/save high scores from file
and I have done old-school empirical tests (run app and see, is it doing a right things in specific scenarios)




Validation helps me test app and check is new countries added to list are correct
This is example of validation for country

public boolean isValid() {

if (id <= 0) {

return false; //as id is start from 1

}
if (!DomUtils.isEmpty(countryName)) {
return false;
}
if (!DomUtils.isEmpty(country)) {
return false;
}
if (!DomUtils.isEmpty(capital)) {
return false;
}
if (region == null) {
return false;
}
return !DomUtils.isEmpty(flagId);
}
}
Note: Incoming data is already checked against is data's correct type (String, int and etc.).


What is a DomUtils? It is my selection of common used Java methods.
I found it, that have own collection of common used methods classes speed up your development.
I wrote my utils, which looks like Apache Common.


Tip: If you want improve your programming skills Apache common source code is a great place, to learn, how to write better quality code.




public static boolean isEmpty(String string) {


return (string == null || string.equals(“”));


}


Conclusions:
  1. Test are important!
  2. You should always write some tests specially for core functionality and places that dealing with validation from user input or files that are modified on regular basis.
  3. If you like TDD, then you must write test everything, before you write code.
  4. It can be a difficult to start. My first adventure with Junit was quite painful. Read about my biggest fail in development blog entry: http://pastorcmentarny.blogspot.co.uko.uk/2011/11/fail-development.html
  5. Do NOT ignore writing test. They will saves you from hot fix releases and 1 stars reviews.


Note: I will update this part, when I add some tests.

Emulator vs Device


Do not use Emulator!
Yes. It is possible to write game using emulator only.
I know one example of game, that was written this way and it works: (Made by  diskthrasher, link  https://play.google.com/store/apps/details?id=uk.me.diskthrasher.monkey),
but believe me you will save 50% of your precious time on development on mobile!


Buy any modern Android device that cost around £100/$150
As early 2013,Minimum which will cover
Android 4.x
CPU:  1Ghz (800Mhz  minimum),1 Core
800×480 (or even 480×360)
and it will be enough for while.


Remember! Testing in emulator  is a very painful process... .You can write a game without using emulator. However, if you want enjoy develop application for Android. BUY SMARTPHONE or cheap TABLET and DO NOT USE EMULATOR!!


That's it for testing.In next part I will give few tips about what to prepare before you add your project into Google Play.
Go to : Add project to Google Play