Testing @ConfigurationProperties in Spring Boot 2.5.X Three years ago, I wrote an article on how to test Spring’s @ConfigurationProperties classes. Since three years are a long time, I just updated the project on GitHub. It works with Spring 2.5.X now! You can find the project right here: https://github.com/tuhrig/Testing_Configuration_Properties And here’s the old post from 2018: https://tuhrig.de/testing-configurationproperties-in-spring-boot What’s it about? The basic […]
Testing @ConfigurationProperties in Spring Boot *** Update *** I updated the example on GitHub to Spring 2.5.X! The latest post on this topic is at https://tuhrig.de/testing-configurationproperties-in-spring-boot-2-5-x. I recently worked on a library for using AWS Kinesis in Spring Boot. As many other libraries, this particular one provided a powerful configuration. To implement the configuration, we used Spring Boot’s @ConfigurationProperties (as […]
A component-based test architecture for Protractor and AngularJS E2E tests Usually, when we talk about architecture, we talk about the application itself. We think about layers, domain models and interfaces to structure our code. Most of the time the tests will follow this architecture. We create one test per service and mirror our code. 12 user-dashboard.service.jsuser-dashboard.service.spec.js This is fine for unit and even integration tests, but […]
Spring-Boot boilerplate project with ActiveMQ and AngularJS During the last couple of months, I wrote a lot blog posts about ActiveMQ (JMS), AngularJS and Spring. Most of those blog posts include some small code snippets, but nothing more. That’s why I decided to setup a “boilerplate project” to show how all those different techniques can go hand in hand in a “real […]
AngularJS tests with mocked HTML documents Most of the time, testing AngularJS applications means testing JavaScript. We test services and we test controllers. But what about directives? What about components? How do we test compiled and injected AngularJS code? Plunker But before we start, here’s the running Plunker with the complete example: https://plnkr.co/edit/PKn4tpUDFWyeqJ2Tb7Ba Testing directives/components Around a year ago I wrote […]
Don’t use transitive dependencies in AngularJS modules Whenever you write an AngularJS application, you will use modules. Modules divide you application into small logical pieces. Some pieces might depended on other, some might be totally independent. 123456 angular.module('UserModule',[]); // no dependency!angular.module('UtilModule',[]); // no dependency!angular.module('MainModule',[ // 2 dependencies! 'UserModule', 'UtilModule']); In the example above, you see three modules. A module called MainModule depending on two other modules, called UserModule and UtilModule. Note that this is […]
Inject mocks with Spring’s @ContextConfiguration One of the biggest strengths of Spring is its ability to make your code testable. By using dependency injection and inversion of control, the Spring context defines which objects will be wired into your beans. This makes it easy to wire services, repositories or what ever you like. But how to wire mocks in your […]
Testing AngularJS directives with Jasmine Directives AngularJS provides a mechanism called directives. Directives are markers in our HTML which Angular will read and use to inject some special behavior to our HTML code. As this sounds a little bit theoretically, let’s look at an example: 1 Enter your name: <input ng-model="name"> In this example the directive ng-model is used which will bind the value of […]
Create random test objects with Java reflection Although Java is an object oriented language, you will often separate our data and your actual business logic. You will write POJOs, entities, domain models and DTOs which you will pass to services, repositories and controllers. If you do so, you will properly need test data for those objects. Often, the data you pass will […]
Everytime a mock returns a mock a fairy dies As I was reading about some Mockito features last week, I stumbled over the following tweet, which really made me laugh: Everytime a mock returns a mock a fairy dies — Damian Guy (@damianguy) 18. Oktober 2009 I actually found the reference to the tweet in the Mockito source code about “deep mocking” and it’s […]