Carlos Alexandro Becker

Tagged in

java

Measuring production code coverage with JaCoCo

Microservices is the new fancy way of doing applications. Yet, most companies still have big and old monoliths in production. In fast evolving software of this size, it’s usual to have lines of code which are never executed in production. Production code coverage reports can help us find those lines.

Distributed Locking with Redis

At ContaAzul, we have several old pieces of code that are still running in production. We are committed to gradually re-implement them in better ways.

Dealing with Maven dependency hell

Every now and then an active java-based project enters in a “dependency hell” state. That usually happens because people keep adding dependencies without checking what comes in transitively nor if that dependency is declared somewhere else already.

Avoid static imports

There are a lot of Java API’s and Frameworks which rely in static methods and the sort. Arguably, this is a bad OOP practice, but lets not enter this particular subject just yet. For example, it is pretty common to write unit tests like this: package blah; import static org.junit.Assert.assertTrue; import org.junit.Test; public class SomeTest { @Test public void testSomething() { assertTrue(1 + 1 == 2); } } While it’s kind of pretty to import static org.

Running a Selenium Grid with docker-compose

At ContaAzul, we had 31 Windows machines powering our Selenium tests - one running the grid and 30 more running clients. Needless to say, this is very expensive. As we are already using Docker to run our builds (on Shippable), we decided to try it out to run Selenium tests too. It was no surprise that Selenium folks already made a ready-to-go set of Docker images. There is an image for the Selenium Grid itself, and the browser images - Chrome and Firefox, also with debug versions - which allow you to access them using VNC to “see what’s happening there”.

Using Mockito's InjectMocks

FYI: Like the previous post, this is a really quick tip. Let’s imagine we have two classes, and one depends on another: Another.java: @Log public class Another { public final void doSomething() { log.info("another service is working..."); } } One.java: @Log @RequiredArgsConstructor public class One { private final transient Another another; public final void work() { log.info("Some service is working"); another.doSomething(); log.info("Worked!"); } } Now, if we want to test One, we need an instance of Another.