The post aims to share my some thoughts of how to learn unit test in java, I will give a little bit more insights on how I am thinking on this. Hope this will bring you more inspirations.
There are two popular testing philosophys a.k.a TDD(Test-Driven Development) & BDD(Behaviour-Driven Development), I started to search some good frameworks with BDD. I knew about BDD from javascipt testing framework, e.g. Mocha, Jasmine, so I am pretty eager to know whether there are any popular BDD frameworks in Java perspective. After reading couples of posts, JBehave and Cucumber are relatively welcomed in the community. Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages, and gains more stars on github. Moreiver, TDD is much more well-known for most Java developer like JUnit, TestNG etc.
Since I am also not quite familiar with JUnit testing, I begin with offical documentation and examples hosted by github wiki pages, which gives me a glimpse about basic JUnit usage and idioms. Then you will find Hamcrest CoreMatchers lib that you can easily invoke assertThat instead of assertTure etc.
Moreover, I search more stars projects on github, you can checkout elasticsearch that will give you a more practical example of how to write code with JUnit test. On the other hand, RxJava use mockito instead of hamcrest. Mockito is a Java mocking that is dominated by expect-run-verify libraries like EasyMock or jMock.
Eventually I am going to start using basic JUnit test with mockito mocking, which looks slim and compact.
References: