Tag Archives: tests

Java

How NOT to write tests and improve coverage

Recently I’ve found nice way of writing tests and improving test coverage.

Check this example:

public enum Fields {
	SEARCH_TYPE,
	SEARCH_CITIES,
	SEARCH_DATES,
    ...
    POINT_OF_SALE;

	public Fields[] getValues() {
		return Fields.values();
	}
}

As you can see this is quite common enum. So how to improve test coverage?

Lets write some test! You can ask how to write tests for enums. Here it goes:

public class FieldsTest extends TestCase
{
    public void test()
    {
        for (Fields type : Fields.values())
        {
            assertEquals(type, type);
        }
    }
}

You can do this if you want to sell your source code to some company and show statistics about test coverage. Something like pig in a poke.

PS. Of course it’s a joke. Never ever do this!

Android

Running junit tests with Android

If you follow best practises you will probably face the same problem as many other developers. You junit test cases will not run. I was getting VM error like this: read more »