我一直在看RoboGuice 2的astroboy示例代码和文档,老实说我很难过.我希望你们都可以帮我解决一些问题.这里的目标是测试模块以确保它正在加载并且IoC正在工作/接线.
我的测试类似于他们的示例:http: //code.google.com/p/roboguice/source/browse/astroboy/src/test/java/org/roboguice/astroboy/controller/Astroboy2Test.java?name = roboguice-2.0b3&R = ba37ef680410c64f7f1fe90f5b7b482958d276b5
我的两种方式不同......我的模块在一个库类中,它的语法相同:
public class MyTestModule extends AbstractModule {
@Override
protected void configure() {
bind(Vibrator.class).toInstance(vibratorMock);
}
}
Run Code Online (Sandbox Code Playgroud)
我还在值文件夹中的库类中有roboguice.xml
<resources>
<string-array name=roboguice_modules>
<item>com.yourdomain.MyTestModule</item>
</string-array>
<resources>
Run Code Online (Sandbox Code Playgroud)
测试项目引用app项目,该项目引用并导出库项目.
在测试项目中它是这样的:
@RunWith(RobolectricTestRunner.class)
public class MyTest {
@Before
public void setup() {
// Override the default RoboGuice module
RoboGuice.setBaseApplicationInjector(Robolectric.application, RoboGuice.DEFAULT_STAGE, Modules.override(RoboGuice.newDefaultRoboModule(Robolectric.application)).with(new MyTestModule()));
}
Run Code Online (Sandbox Code Playgroud)
在设置过程中,它总是出现错误,带有某种空异常.我已经解决了这个问题,特别是newDefaultRoboModule方法.我知道Robolectric.application不是null,我知道新的MyTestModule也不是null.虽然在单步执行调试器时,我发现MyTestModule.binder为null,所以我不知道这是不是问题.
错误堆栈跟踪:
java.lang.NoClassDefFoundError: javax/inject/Provider
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at javassist.Loader.findClass(Loader.java:379)
at com.xtremelabs.robolectric.bytecode.RobolectricClassLoader.findClass(RobolectricClassLoader.java:72)
at javassist.Loader.loadClass(Loader.java:311)
at java.lang.ClassLoader.loadClass(Unknown Source) …Run Code Online (Sandbox Code Playgroud) dependency-injection android-2.2-froyo roboguice robolectric
我看过基础知识和课程,但是对匕首(甚至匕首2)不熟悉我不知道我怎么想用这个
这是匕首意图服务:https://google.github.io/dagger/api/latest/dagger/android/DaggerIntentService.html
我理解android意图服务和实现的基础知识,但我似乎无法找到DaggerIntentService的信息(我也很难找到DaggerService的信息)
我的目标是使用TDD构建它,但我真的只需要了解实现基于匕首的服务的工作流程
谢谢,凯莉
我有一个 PercentView 类,我正在尝试设置一个测试,我想验证它是否被绘制到正确的大小。我已经将它用于一个简单的栏,但现在我想要它上面的图像/图标,它是一个可绘制的(实际上是矢量)。
关于这个的一些注意事项:
app_enabled.xml,它是main\res\drawable\app_enabled.xml.Robolectric 3.5.1我已经声明了样式:
<declare-styleable name="PercentageView">
<attr name="image" format="integer" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
和观点:
public class PercentageView extends View {
private int _activeColor;
private int _barBackgroundColor;
private float _barHeight;
private Drawable _icon;
private Paint _barBackgroundPaint;
private Paint _barActivePaint;
private int _percent;
public PercentageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray args = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.PercentageView,
0,
0);
try {
_icon …Run Code Online (Sandbox Code Playgroud) 最近我一直在为我的本地项目添加一些功能,而我正在努力解决这个问题.缺点是NHibernate给我的一句话:
Found shared references to a collection: Page.Menus
Run Code Online (Sandbox Code Playgroud)
它的简单部分是,我只想保存将菜单绑定到页面的关系映射,您可以在下面的参考中看到它PageMap.我应该补充一点,加载数据效果很好,这是拯救我的行为.
昨天我花了很多时间在这里挖掘,以及好的网络,试图找到答案,我只是一直在罢工.也许这对我来说很糟糕,但我觉得我尝试了一切.如果你知道它在哪里可以提供吗?(谢谢)
对于实际细节,我试图简化正在发生的事情.我添加了PageReposity,UnitOfWork和代理对象,以及它们的映射.
我朦胧的地方是级联,以及如何保存关系表(多对多)
对于第一部分,这是我保存(添加)时发生的情况.我实际上已经做了几个方法PageRepository.因为我正在努力Add(),我把它包括在这里:
public override bool Add(Page entity)
{
UnitOfWork.Save(entity);
/* I have also tried doing the following below, which doesn't help
for (var index = 0; index < entity.Menus.Count; index++)
{
UnitOfWork.Save(entity.Menus[index]);
}
*/
UnitOfWork.Commit(); // bam, error!
return true;
}
Run Code Online (Sandbox Code Playgroud)
在UnitOfWork我设置的构造函数如下(在ISession的每次通过ninject注入像这样:
// DomainModule
...
Bind<ISFactory>().To<NHibernateSessionFactory>()
.InSingletonScope()
.WithConstructorArgument("connectionString", _connectWeb);
...
Run Code Online (Sandbox Code Playgroud)
//回到 UnitOfWork
...
private ISession Session { get; set; }
... …Run Code Online (Sandbox Code Playgroud) 我在提交表单数据后只能渲染组件时遇到麻烦。
所以我有一个具有基本渲染的应用程序:
(<div>
<form onSubmit={this.onSubmit.bind(this)}>
</form>
<Results/>
</div>);
Run Code Online (Sandbox Code Playgroud)
这个想法是onSubmit Results仅在提交时才将一些数据转储到组件中。
现在,老实说,该应用将在其状态内具有值:
this.state = {
length : 0,
timeInSeconds: 0
}
Run Code Online (Sandbox Code Playgroud)
因此,我只希望它在用户单击“提交”按钮并且执行onSubmit方法时呈现或重新呈现此对象。
抱歉,这不是我想要的,但是任何建议或指导都很棒!
谢谢,凯利
我正在使用最新的Android Studio 3 Beta(当前是Beta 4),但似乎无法获得它来生成所需的Dagger类。
在我这边,我创建了一个空项目。然后,我将活动重命名为与匕首笔记YourActivity相匹配。请参阅https://google.github.io/dagger/android.html中的 “注入活动对象” ,其中显示了以下内容:
@Subcomponent(modules = ...)
public interface YourActivitySubcomponent extends AndroidInjector<YourActivity> {
@Subcomponent.Builder
public abstract class Builder extends AndroidInjector.Builder<YourActivity> {}
}
@Module(subcomponents = YourActivitySubcomponent.class)
abstract class YourActivityModule {
@Binds
@IntoMap
@ActivityKey(YourActivity.class)
abstract AndroidInjector.Factory<? extends Activity>
bindYourActivityInjectorFactory(YourActivitySubcomponent.Builder builder);
}
@Component(modules = {..., YourActivityModule.class})
interface YourApplicationComponent {}
@ActivityScope
@ContributesAndroidInjector(modules = { /* modules to install into the subcomponent */ })
abstract YourActivity contributeYourActivityInjector();
public class YourApplication extends Application implements HasActivityInjector {
@Inject DispatchingAndroidInjector<Activity> dispatchingActivityInjector;
@Override
public …Run Code Online (Sandbox Code Playgroud) android dagger android-gradle-plugin dagger-2 android-studio-3.0
android ×3
dagger-2 ×2
robolectric ×2
c#-4.0 ×1
dagger ×1
javascript ×1
junit4 ×1
nhibernate ×1
reactjs ×1
roboguice ×1