You could also change from unit test to integration test in case a
component depends on other components, when you do that you can register
your mocks as a normal service and you don't have to make changes to your
code just to be able to test it.
Regards,
Bram
2014-09-16 17:35 GMT+02:00 Konstanti
Setter is ok, provided the bean is visible via an interface to other
bundles. But it can create issues on bigger projects with lots of
developers. I.e. A developer can use the setter to change the field on
production code with disastrous results. Or even on test code that runs
inside the container,
The manner in which you inject dependencies in your unit test should be
exactly the same as when you deploy the component to a production
environment.
If you inject into fields in production, you should inject into fields
in your test also.
If your fields are private, and you're running DI framewo
Why not just create a setter method for this dependency and use that from the
unit test? I've never understood the desire to inject directly into private
fields.
I also didn't understand your explanation about polluting state. What does the
state matter if this is a genuine unit test?
Regar
I want to write a unit test which will run outside of the container. I
want to mock dependencies. I don’t mind about lifecycle methods as my
service won’t use them (or I don’t need / can mock them).
Say for example I am writing A that uses B which downloads a big json file
from the internet. I wan
You don't provide enough information to know what you are doing, and I don't
understand what you mean by a unit test.
If you are writing a DS component and using Felix DS annotations, note that the
@Reference on a field without accessors results in byte code generation of
accessor methods. You
Well, that¹s similar to the forTesting factory I mention but with the
drawback that the state of A is corrupted until the JVM terminates. By
corrupted I mean that my mock will be part of A until either the jvm stops
or something else injects a different thing to A.b. If the mock is set
this way whi
Why not set the field b in your object manually to the mock B for unit testing?
Just assign it to the field. If you insist on having it private you
can call 'Field.setAccessible(true)' in your unit test and assign it
using reflection...
Best regards,
David
On 16 September 2014 14:39, Konstantin
Hi, say I got a service A, which has a
@Reference private B b;
Now I want to write a unit test and mock B, how can I inject the mocked
dependency?
Only reasonable thing I found so far is to have a static factory method on A,
public static A forTesting(B b) { … }
Thanks,
Kostas
OK, my bad, I asked the question poorly.
It of course works with private-package as well (I just used the export in
my simple test).
What I intended to ask was, why the stereotype class needs to be included
in the bundle using it? In another words - isn't it enough that the bundle
imports the packa
Hi
I have my jars in my local maven repo, they typically come from central.
I develop my own bundles and deploy to my remote OBR using
maven-bundle-plugin: the bundles are uploaded and the repository.xml is
updated. Good.
Now I want also to push the needed dependency jars coming from central
11 matches
Mail list logo