小编din*_*rui的帖子

@InjectMocks,构造函数或初始化块抛出异常

当我使用时@InjectMocks,发生了异常。我的代码如下所示:

class A {
    private X x;
    private Y y;
    public A(String ip, int port) {
       this(someMethodCall(ip, port)); //
    }

    private A(X x) {
        this.x = x;
        this.y = new Y();
    }
}
UT:
public class ATest() {
    @InjectMocks A a;
    @Mock X x;
    @Mock Y y;
    @Test ...
}
Run Code Online (Sandbox Code Playgroud)

它会抛出 NPE,有人可以帮助我吗?

org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'channel' of type 'class Juinit3.Channel'. You haven't provided the instance at field declaration so I tried to construct the instance. …

java junit unit-testing mockito

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

关于bazel概念的一些问题

我正在学习 Bazel 并且对许多基本概念感到困惑。

    load("//bazel/rules:build_tools.bzl", "build_tools_deps")
    build_tools_deps()      //build_tools_deps is macro or rules?

    load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
    gazelle_dependencies()  //what about the @ mean exactly? where is the bazel_gazelle ?
    native.new_git_repository(...) //what about the native mean?
Run Code Online (Sandbox Code Playgroud)

什么定义称为函数?什么定义是规则?

bazel

7
推荐指数
1
解决办法
387
查看次数

如何在golang中将http响应体解析为json格式?

我得到一个响应主体。正文的格式如下:

  [
    {
       "id":1,
       "name":"111" 
    },
    {
       "id":2,
       "name":"222" 
    }
  ]
Run Code Online (Sandbox Code Playgroud)

我想将正文解析为 json 结构,我的代码如下:

type Info struct {
      Id uint32 `json:id`
      Name string `json:name`
  }

  type Response struct {
      infos []Info
  }

  v := &Response{}
  data, err := ioutil.ReadAll(response.Body)
  if err := json.Unmarshal(data, v); err != nil {
      log.Fatalf("Parse response failed, reason: %v \n", err)
  }
Run Code Online (Sandbox Code Playgroud)

它总是报错:cannot unmarshal array into Go value of type xxx,有人可以帮忙吗?

json go

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

使用cgo时的多重定义

package main

/*
int add(int a, int b) {
    return a + b;
}
*/
import "C"
import "fmt"

func main() {}

func Test1() {
    fmt.Println(C.add(1, 3))
}

//export Test2
func Test2() {

}
Run Code Online (Sandbox Code Playgroud)

编译程序:

dingrui@dingrui-PC:~/Projects/gotest/array$ go build -o libtest.so -buildmode=c-shared main.go 
# command-line-arguments
/tmp/go-build043762604/b001/_x002.o: In function `add':
./main.go:5: multiple definition of `add'
/tmp/go-build043762604/b001/_x001.o:/tmp/go-build/main.go:5: first defined here
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

如果我删除“//export Test2”行,它就会成功编译。

go cgo

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

标签 统计

go ×2

bazel ×1

cgo ×1

java ×1

json ×1

junit ×1

mockito ×1

unit-testing ×1