小编ris*_*ide的帖子

Mockito for int primitive

如果我使用Wrapper类类型变量作为参数Mockito测试用例正在通过但是,如何为int基本类型变量编写Mockito测试用例,这是ServiceImpl中方法的参数.

java mockito

26
推荐指数
2
解决办法
2万
查看次数

PowerMock ECLEmma coverage issue


We are using EasyMock and PowerMock with JUnit. The coverage tool used is ECLEmma. With EasyMock, it shows the coverage properly in green (as covered). However, for the code that is unit tested with PowerMock, the coverage is shown in red (uncovered). Have read similar questions on the web. However, just wanted to check if there is a solution for this.

Thanks
Venkatesh

java junit easymock

24
推荐指数
3
解决办法
2万
查看次数

如何在Spring Boot中获取本地服务器主机和端口?

我正在启动一个Spring Boot应用程序mvn spring-boot:run.

@Controller的一个需要有关应用程序正在侦听的主机和端口的信息,即localhost:8080(或127.x.y.z:8080).在Spring Boot文档之后,我使用了server.addressserver.port属性:

@Controller
public class MyController {

    @Value("${server.address}")
    private String serverAddress;

    @Value("${server.port}")
    private String serverPort;

    //...

}
Run Code Online (Sandbox Code Playgroud)

在启动应用程序时mvn spring-boot:run,我得到以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: ... String ... serverAddress; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.address' in string value "${server.address}"
Run Code Online (Sandbox Code Playgroud)

双方server.addressserver.port不能自动装配. …

java spring-boot

19
推荐指数
6
解决办法
7万
查看次数

测试使用EasyMock调用void方法

这可能吗?我尝试过,EasyMock.expectLastCall().times(0);但EasyMock抱怨时间必须> = 1

java unit-testing easymock

16
推荐指数
4
解决办法
2万
查看次数

Mockito - thenReturn总是返回null对象

我正在尝试实现Mockito来测试一个特定的方法,但.thenReturn(...)似乎总是返回一个null对象,而不是我想要的:

切:

public class TestClassFacade {

  // injected via Spring
  private InterfaceBP bpService;

  public void setBpService(InterfaceBP bpService) {

      this.bpService = bpService;
  }

  public TestVO getTestData(String testString) throws Exception {

    BPRequestVO bpRequestVO = new BPRequestVO();

    bpRequestVO.setGroupNumber(testString) ;
    bpRequestVO.setProductType("ALL") ;           
    bpRequestVO.setProfileType("Required - TEST") ;

    IBPServiceResponse serviceResponse = bpService.getProduct(bpRequestVO);  //PROBLEM

    if (serviceResponse.getMessage().equalsIgnoreCase("BOB")) {

        throw new Exception();

    } else {

        TestVO testVO = new TestVO();
    }

    return testVO;
  }

}
Run Code Online (Sandbox Code Playgroud)

弹簧配置:

<bean id="testClass" class="com.foo.TestClassFacade">

   <property name="bpService" ref="bpService" />

</bean>

<bean id="bpService" class="class.cloud.BPService" />
Run Code Online (Sandbox Code Playgroud)

Mockito测试方法: …

java null mockito

16
推荐指数
4
解决办法
3万
查看次数

单元测试spyOn在angular2中的可观察服务

我有一个服务(ChildService),它依赖于另一个服务(InteractWithServerService).以后的服务(InteractWithServerService)用于进行服务器调用并返回"any"类型的observable.为简单起见,我们假设它返回了observable.我正在尝试为ChildService编写单元测试.

ChildService

@Injectable()
export class ApplicationService {
    constructor(private  interactWithServerService:InteractWithServerService){;}

    public GetMeData():string {
        var output:string;       
        this.interactWithServerService.get("api/getSomeData").
           subscribe(response =>{console.log("server response:", response);
           output=response});        
         return output;
    }
}
Run Code Online (Sandbox Code Playgroud)

ServerInteractionService

@Injectable()
export class InteractWithServerService {        
    constructor(private http: Http) {
        ;
    }    
    get(url: string): Observable<any> {        
        return this.http.get(this.url);
    }       
}
Run Code Online (Sandbox Code Playgroud)

当我模拟依赖服务时,测试用例工作正常.即

class MockInteractWithServerService {
    get() {
        return Observable.of("some text");
    }           
}

describe('Service:ChildService', () => {
    let childService: ChildService;

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
             { provide: InteractWithServerService, useClass: MockInteractWithServerService },
                ChildService],
        });


    beforeEach(inject([ChildService], (actualService: ChildService) => …
Run Code Online (Sandbox Code Playgroud)

unit-testing typescript angular

12
推荐指数
1
解决办法
2万
查看次数

如何在angular2中获取ag网格中所选行的数据?

我在angular2中设置ag-grid工作正常,但我无法获得所选行的值...我的控制台窗口中没有错误......这就是我初始化网格的方式......

import {Component} from 'angular2/core';


@Component({
selector: 'aggride',
template: `

<div class="tr-card" >
<ag-grid-ng2  #agGrid of mgrid   class="ag-fresh"   rowHeight="40px"    
               [columnDefs]="columnDefs" 
                [rowData] = "rowData"
     enableCellExpressions="true"  
 enableSorting="true"  
  unSortIcon="true"
rowSelection="single"
(getSelectedRows) = "getSelectedRows()"
(onSelectionChanged) = "onSelectionChanged()"
>
</ag-grid-ng2>
</div>
`,
directives: [(<any>window).ag.grid.AgGridNg2],
})
Run Code Online (Sandbox Code Playgroud)

这个我的代码在类中获取所选值

export class AgGride {
gridOptions = {
    columnDefs: 'columnDefs',
    rowData: 'rowData',
    rowSelection: 'single',
    getSelectedRows: 'getSelectedRows',
    onSelectionChanged: 'onSelectionChanged'
};

columnDefs = [
    { headerName: "Make", field: "make", editable: true },
    { headerName: "Model", field: "model", editable: true },
    { headerName: …
Run Code Online (Sandbox Code Playgroud)

typescript ag-grid angular

10
推荐指数
2
解决办法
3万
查看次数

如何使用角度2组件的路由器打开新的浏览器选项卡?

我有一个角度2组件,需要导航到另一个路线,但在不同的浏览器选项卡中.下面的代码在同一浏览器选项卡中导航.

    import { Component } from '@angular/core';
    import { Router } from '@angular/router';

    @Component({
         templateUrl: 'quotes-edit.component.html'
    })

    export class QuoteComponent {
         constructor(private router: Router) {
         }

         this.router.navigate(['quote/add']);
    }
Run Code Online (Sandbox Code Playgroud)

typescript angular2-routing angular

10
推荐指数
1
解决办法
8031
查看次数

招摇使用@ApiParam或@ApiModelProperty?

以下注释都适用于向swagger-ui文档添加元数据.应该首选哪一个,为什么?

public class MyReq {

    @ApiModelProperty(required = true, value = "the persons name")
    @ApiParam(required = true, value = "the persons name")
    private String name;
}

@RestController
public class MyServlet {
   @RequestMapping("/") 
   public void test(MyReq req) {

   }
}
Run Code Online (Sandbox Code Playgroud)

java swagger swagger-ui swagger-2.0

10
推荐指数
1
解决办法
3万
查看次数

在RxJS 5.5中测试和模拟可调运算符

在lettable operator之前,我做了一个帮助来修改debounceTime方法,所以它使用了一个TestScheduler:

export function mockDebounceTime(
    scheduler: TestScheduler,
    overrideTime: number,
): void {
    const originalDebounce = Observable.prototype.debounceTime;

    spyOn(Observable.prototype, 'debounceTime').and.callFake(function(
        time: number,
    ): void {
        return originalDebounce.call(
            this,
            overrideTime,
            scheduler,
        );
    });
}
Run Code Online (Sandbox Code Playgroud)

因此,以下Observable的测试很简单:

@Effect()
public filterUpdated$ = this.actions$
    .ofType(UPDATE_FILTERS)
    .debounceTime(DEFAULT_DEBOUNCE_TIME)
    .mergeMap(action => [...])
Run Code Online (Sandbox Code Playgroud)

对于lettable运算符,filterUpdated $ Observable的编写方式如下:

@Effect()
public filterUpdated$ = this.actions$
    .ofType(UPDATE_FILTERS)
    .pipe(
        debounceTime(DEFAULT_DEBOUNCE_TIME),
        mergeMap(action => [...])
    );
Run Code Online (Sandbox Code Playgroud)

我不能修复debounceTime运算符了!如何将testScheduler传递给debounceTime运算符?

typescript rxjs5 ngrx-effects

9
推荐指数
1
解决办法
3244
查看次数