鉴于以下代码,我尝试测试ngOnChangesAngular2 的生命周期钩子:
import {
it,
inject,
fdescribe,
beforeEachProviders,
} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {Component, OnChanges, Input} from '@angular/core';
@Component({
selector: 'test',
template: `<p>{{value}}</p>`,
})
export class TestComponent implements OnChanges {
@Input() value: string;
ngOnChanges(changes: {}): any {
// should be called
}
}
fdescribe('TestComponent', () => {
let tcb: TestComponentBuilder;
beforeEachProviders(() => [
TestComponentBuilder,
TestComponent,
]);
beforeEach(inject([TestComponentBuilder], _tcb => {
tcb = _tcb;
}));
it('should call ngOnChanges', done => {
tcb.createAsync(TestComponent).then(fixture => {
let testComponent: …Run Code Online (Sandbox Code Playgroud) 我目前正试图安装BarcodeScanner插件的Phonegap Version 3.0.0.我找不到任何关于如何正确安装它的工作文档,我自己也没弄明白.所以我真的很感激任何帮助!
先感谢您!最好的问候,安德烈亚斯
我正在使用Mockito进行JUnit测试.所以从我想要测试的代码中使用给定的A类:
class A{
public A(){}
public final String a(String x){
return "A.a: " + x;
}
}
Run Code Online (Sandbox Code Playgroud)
我想用另一个方法调用替换方法调用Aa与相同的参数和相同类型的返回值.正如您所看到的,不可能通过扩展类来覆盖方法a,因为它是最终的.所以我现在拥有的另一个B类方法是Bb:
class B{
public B(){}
public String b(String x){
return "B.b: " + x;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想确保每次从代码中调用Aa时,都会使用Bb的返回值.是否有可能通过Mockito(类似的东西Mockito.when(A.a(x)).thenReturn(B.b(x));)实现这一点,但使用相同的参数x,而不知道x的值?
任何帮助将不胜感激,谢谢你提前!
尝试使用 Robolectric 在 Android 库项目上运行 JUnit 测试时,出现以下错误:
java.lang.RuntimeException: java.lang.InstantiationException
at com.xtremelabs.robolectric.ApplicationResolver.newApplicationInstance(ApplicationResolver.java:56)
at com.xtremelabs.robolectric.ApplicationResolver.resolveApplication(ApplicationResolver.java:36)
at com.xtremelabs.robolectric.RobolectricTestRunner.createApplication(RobolectricTestRunner.java:246)
at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:233)
at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:177)
at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:157)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.xtremelabs.robolectric.ApplicationResolver.newApplicationInstance(ApplicationResolver.java:54)
... 20 more
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是我在测试中犯了一个错误,所以我尽可能地简化了测试运行:
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import …Run Code Online (Sandbox Code Playgroud) 我正在使用的服务器使用仅限http的cookie发送会话ID.为了使其在WP8上运行,我已经在设备的Internet Explorer设置中启用了cookie.这适用于我的所有AJAX请求.但现在我必须从服务器下载一个文件,因此我正在使用文件传输插件,但我总是得到HTTP Status 401 - Http Request not attached to a session
有没有办法解决这个问题,以便包含JSESSIONID的cookie头与下载请求一起发送?
我从网络服务器获取 png 图像的原始图像数据,并希望将其用作 div 元素的背景图像。如果不先将数据保存为图像文件,这可能吗?
cordova ×2
javascript ×2
junit ×2
junit4 ×2
unit-testing ×2
android ×1
angular ×1
cookies ×1
css ×1
html ×1
java ×1
mockito ×1
robolectric ×1