Hi Petr, On Mon, Jun 22, 2015 at 3:02 PM, Petr Shypila <ikrump...@gmail.com> wrote: > ...So as I understand for now Sling Mocks is the preferable and most modern > way to write unit tests. Is that correct?...
Preferable in certain cases...I'd say in order of setup complexity / performance you have 1. unit tests 2. generic mocks (Mockito etc) or Sling Mocks 3. pax exam 4. Sling integration tests under launchpad/testing The general rule is to use the first of those options that works for what you need to test. But for option 2. now that we have Sling Mocks they are generally preferable to generic mocks, as they fit the Sling environment better. > ...What about JCR data store? Does it save data between tests and should take > care of that?... Not sure which one you mean, if you use a RepositoryProvider from sling.commons.testing then yes, the data persists through all tests. It makes them faster as the repository is setup only once, but you need to implement isolation in your tests, using unique paths etc. I don't know how that works with the Sling Mocks variant, I haven't used that so far. > > A question about PaxExam. Right now I have problems with > BundleContentLoader initialization. Every time I getting > ClassNotFoundException... As soon as you move up to pax exam you're in an OSGi environment, where only java packages that are exported by the bundle under test are available. The package that contains BundleContentLoader is not exported by the bundle under test (you could see that at /system/console/bundles in a Sling instance, or look at the bundles META-INF/MANIFEST.MF, or look for package-info.java source files in the source code to find out), so you don't see it from a pax exam test. Generally you'll only inject service APIs in those tests, you can look around the code base for tests that contain @Inject for examples. So pax exam is good for black-box testing at the OSGi level, which is a good way to test services IMO. -Bertrand