problem in running with maven tests repeatedly

3 views
Skip to first unread message

wing

unread,
Apr 8, 2009, 8:41:14 PM4/8/09
to Salve
i am using salve with maven

since salve instruments the byte codes directly, the instrumented
codes are directly placed at the target/classes after the first "build/
test"

but if i run
> mvn test
again, my test fails when my code calls the setter because the salve
removed the setter and complained:

Attempted to write to field `xxx` that has been removed from class
`yyy` by salve's dependency instrumentor


does it mean that i need to run the maven test with a clean every
time? then this will be quite annoying and time consuming

Igor Vaynberg

unread,
Apr 8, 2009, 8:55:35 PM4/8/09
to salve...@googlegroups.com
you should not use setters, or even have them for dependency fields.
the reason is that it does not scale because if you have nested
dependencies you would have to manually wire them all and provide
public setters even for private dependencies.

it is much easier to simply install mocks into the dependency library
and have those injected by salve.

eg

class mocklocator implements locator {
private final Object dependency;
public mocklocator(Object dependency ) { this.dependency=dependency; }
public Object locate(Key key) {
if (key.getType().equals(dependency.getClass()) {
return dependency;
} else { return null; }
}
}

class FooTest {
setup() { DependencyLibrary.clear(); }
teardown() { DependencyLibrary.clear(); }

testFoo() {

MockDependency dependency=new MockDependency();
DependencyLibrary.addLocator(new mocklocator(dependency));

Foo foo=new Foo();
foo.dosomething();
^ foo can now get dependency injected into it
}
}

-igor
Reply all
Reply to author
Forward
0 new messages