[VS Code Tips] How to Make AssertJ Be Static Imported in VS Code

After installing the famous Java plugin written by RedHat, VS Code will become into a powerful Java IDE, which is far beyond other editors, such as Sublime, Notepad++.

Today’s tip will show you how to static import AssertJ in VS Code. AssertJ helps you to write assertions in unit testing. Compared to Hamcrest, someone, like me, think AssertJ’s API and syntax make more sense.

First, you need to introduce it. In maven, it’s very straightforward. Simply define a new dependency in pom.xml.

Next step is to update a configuration “java.completion.favoriteStaticMembers“. Otherwise, assertThat() will be the one in Hamcrest in the auto-completion. Remove “org.junit.Assert.*” from the user configuration and add “org.assertj.core.api.Assertions.*” instead.

Now, AssertJ will be statically imported into your unit testing.