I have begun to use ScalaTest to test my Java code and I like it (I've read the "Testing in Scala" book).
Recently I've been trying to test some java Spring code that contain fields which are marked private
and @Autowired
. There are no setter methods for these fields.
I realise that I could easily test them using JUnit + Mockito using the annotations @InjectMocks
and @Mock
, however, I would like to test them using ScalaTest and a mocking framework (such as Mockito or ScalaMock).
My question: Can Scalatest + Mockito be used to mock out private fields or do these frameworks require that my java classes have a public
setter method defined for my private
+ @Autowired
fields?