Separate execution of unit and integration tests in Gradle

Sep 22, 2018
java, gradle, testing

During development process, we often write unit and integration tests. While unit tests verify corectness of the small pieces of code, integration tests verify software as a whole project and sometimes can treat it as a black box where concrete results are expected. During development of the REST API, we can write integration tests for such API with REST Assured. Integration tests are usually slower, because they need to start the server and sometimes do other stuff. ...

Excluding generated code from JaCoCo report

Sep 18, 2018
testing, java, gradle

I recently wrote a simple java app with Dagger 2 as a DI container and Gradle as a build system. I wanted to generate unit test coverage report for this app, so I used Jacoco. In my build.gradle file I configured JaCoCo as follows: plugins { id 'jacoco' } jacocoTestReport { reports { xml.enabled = true html.enabled = true } } Now, I could type: ./gradlew test jacocoTestReport Report was generated in build/reports/jacoco/ directory. ...

Testing exceptions

Sep 4, 2018
java, testing

In Java, we can test exceptions via unit tests in a few different ways. In this article, I’ll present common methods of doing that. Nevertheless, I suppose we there are different methods as well. First method is basically wrapping a method call with try-catch block, assigning an exception to a variable and performing appropriate assertion. In these examples, I’m using JUnit for unit tests and Truth for assertions. @Test public void shouldTestExceptionWithTryCatch() { Exception caughtException = null; try { throw new RuntimeExcetpion("message"); } catch (final Exception e) { caughtException = e; } assertThat(caughtException). ...

Unit test coverage report with Travis CI for Robolectric on Android

Mar 19, 2017
android, testing

Introduction # Some time ago, I’ve written an article about Test coverage report for Android application. It got some interest (many comments below article and many visits according to Google Analytics), so I decided to refresh this topic. Previously, I’ve written instrumentation unit tests, which needed to be executed on a real device or an emulator. It’s a good approach when you want to test functionalities strongly connected with the device. ...

Lifting quality of a shell script

Nov 30, 2016
testing, linux

Introduction # In release cycle of our team at work, we need to perform so-called system tests. In order to do that, we need to log into Artifactory, search for the latest release package, check if it’s up to date, download it, unzip it, install internal configuration recipe, compile, initialize & run it. Not all of that can be easily automated, but I thought that at least searching & downloading phase can be done from the terminal in a semi-automated way. ...

Test coverage report for Android application

Jun 3, 2015
android, testing

Update: see newer article about Unit test coverage report with Travis CI for Robolectric on Android. For a long time, I wasn’t able to find the right way to generate test coverage reports for Android instrumentation unit tests created with AndroidJUnit4 runner. In the past I’ve found many solutions, but none of them was working or they were compatible only with Robolectric, which I currently don’t use. Other developers also stopped using it for the new projects. ...

Mockito on Android

Mar 15, 2015
android, testing

Overview # When we write unit tests for an Android application, sometimes there’s a necessity to mock some classes or interfaces. Instead of writing implementations dedicated for unit tests by hand, we can use Mockito library. We can read article about Mockito on Android on Square’s blog. Mockito can make our tests cleaner and better. It can be used both in classic Java projects and Android projects. It’s one of the most popular mocking framework in Java and if you’re a Java developer who writes unit tests and tries to apply TDD approach, you should be familiar with it. ...