#Testing - Spring & Java

1 messages · Page 1 of 1 (latest)

raw nimbus
#

What are the most modern / simple / easy testing techniques for plain Java apps and for spring projects?

Spring's documentations uses JUnit with TestRestTemplate or Mockito & MockMVC
Which of these is better for large projects? What if the goal is easy-ness of writing tests?
Are there better alternatives?

spice flareBOT
#

<@&1004656351647117403> please have a look, thanks.

dreamy grove
#

You can use mockito with JUnit.

#

JUnit, Mockito, AssertJ, Testcontainers, awaitility and datafaker are some pretty commonly used libraries.

raw nimbus
#

Oo, some of those are new to me - will need to go through those

#

Do you have any sample repos I can refer to which test rest apis? (really - really extensively, as if it was a large rest api)
everything from data validation, response codes, json serialization, database schema etc?

dreamy grove
raw nimbus
#

Also how do I decide whether to use TestRestTemplate or something a bit more low level (?) like mockMvc? the resttemplate testing code seems more concise and cleaner - from what I'm seeing the only difference is that mockMvc doesnt have the server overhead

dreamy grove
#

Just relying on mocks truly is often not the most efficient way to test code. Should data access code mock out the database? Should a GraphQL or REST service just test its data fetchers as Java methods? You will not only learn why the answer to these questions is often “no”, but you will learn the techniques to best test such code. You will lear...

▶ Play video
raw nimbus
#

I currently have the petclinic repo open side by side haha and I'm going through the spring.academy learning path - my only gripe is the mismatch between the way both do things, academy uses @RestController and a simpler design

#

altho thats probably a good thing lol, the spring.academy course was a bit on the simpler side so maybe I just should understand petclinic properly

#

Thanks for all these resources, for some context I'm coming over from the Python world and connecting the dots have been fun - recently started an internship where they're making us build a spring app to learn in 2 weeks (!) and god I wish I could just do deep-dives into stuff without having to rush through things, hate having half the picture of things