在Cygwin64上编译cgo lib:“ld:找不到-lmingw32”(Compile cgo lib on Cygwin64: “ld: cannot find -lmingw32”)
我正在尝试在Windows上使用cgo库,即
github.com/mattn/go-sqlite3
我使用Cygwin64并安装了所有“开发”软件包,因此可以使用gcc。
但是运行
go get github.com/mattn/go-sqlite3
导致:/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
如果我在Cygwin安装程序中搜索“mingwex”和“mingw32”,我没有得到任何结果。 我在寻找错误的名称还是在64位系统上没有?
或者有更好的方法在Windows上使用该库?
请注意,README声明了这一点
但是,如果您使用go install github.com/mattn/go-sqlite3安装go-sqlite3,则不再需要gcc来构建您的应用程序
但如果我使用
go install
我会收到相同的错误消息。$ go version go version go1.6.2 windows/amd64
I'm trying to use a cgo library on Windows, namely
github.com/mattn/go-sqlite3
I use Cygwin64 and installed with all "Development" packages, so gcc is availabe.
But running
go get github.com/mattn/go-sqlite3
results in:/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex /usr/lib/gcc/x86_64-pc-cygwin/5.3.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
If I search for "mingwex" and "mingw32" in the Cygwin installer, I get no results. Am I looking for the wrong names or are they not available on 64 bit systems?
Or is there a better way to use the library on Windows?
Note that the README states that
However, if you install go-sqlite3 with go install github.com/mattn/go-sqlite3, you don't need gcc to build your app anymore
but I get the same error message if I use
go install
.$ go version go version go1.6.2 windows/amd64
原文:https://stackoverflow.com/questions/37497354
最满意答案
你不要覆盖你的模拟
mockCrypto = CryptoManager.getCrypto();
经测试
@Test(expected=RuntimeException.class) public void testdecrpyMcpDataExceptions() throws Exception { Crypto mockCrypto = mock(Crypto.class); doThrow(new RuntimeException()).when(mockCrypto).closeSession(); mockCrypto.closeSession(); }
工作正常。
don't you overwrite your mock at
mockCrypto = CryptoManager.getCrypto();
Tested
@Test(expected=RuntimeException.class) public void testdecrpyMcpDataExceptions() throws Exception { Crypto mockCrypto = mock(Crypto.class); doThrow(new RuntimeException()).when(mockCrypto).closeSession(); mockCrypto.closeSession(); }
works fine.
相关问答
更多-
是您的主类创建其依赖项的实例(实现您提到的那些接口)? 如果可能,您最好更改主类以遵循依赖注入模式。 然后,您将通过构造函数或通过setter为我们的主类提供其依赖项。 这些依赖项可以是用于测试的模拟或生产代码中的真实实现。 稍微修改了guilhermerama的例子。 YourMainClass yourMain = new YourMainClass(anInterfaceMock); Is it your main class that creates the instances of its de ...
-
你对模拟的假设是不正确的。 当您的测试代码实例化新对象( new RequestWrapper() )时,不使用使用Mockito.mock()创建的Mockito.mock() (除非您使用例如Powermock模拟构造函数,但这是另一个故事)。 Sorry I got wrong. Only the instance explicitly mocked become a mock. The others are object of the real classes. I got wrong becaus ...
-
在Mockito中加载一个模拟类(Load a mocked class in Mockito)[2022-03-25]
它绝不可能是ClassA以外的任何东西 ......除了它,在你的测试中。 测试代码是真正的代码,虽然这并不意味着它应该潜入您的生产应用程序,但它确实意味着您需要为所有用例编写所需的灵活性 ,包括测试 。 Mockito通过子类工作: mock(Foo.class)或@Mock Foo mockFoo mockFoo创建的@Mock Foo mockFoo实际上是Mockito创建的代理子类,它覆盖了Foo的每个方法。 从描述中可以看出,Mockito因此不能改变每个 Foo对象的行为,尤其是不能改变new ... -
每个方法的Mockito默认实现由RETURNS_DEFAULTS给出,除非另有配置,否则延迟到ReturnsEmptyValues : 每个Mockito模拟的默认答案。 返回原始返回方法的适当原语 返回原始包装类的一致值(例如,int-returning方法返回0,Integer-returns方法返回0) 返回集合返回方法的空集合(适用于最常用的集合类型) 返回toString()方法的mock的描述 如果引用等于则返回零,否则对于Comparable#compareTo(T other)方法返回非零 ...
-
MyController类中的第二行myMethod(String someId, SomeHeaderParams someHeaderParams) : 有一个方法myClientService.getHeaderParams(SomeHeaderParams)的调用:我没有看到该调用的任何模拟配置,所以它应该返回null ,并且当调用buildRequest(String, Map, Map)方法时,它应该重新调用null作为第二个参数。 anyMap()匹配器anyMap() ,这就是为什么它返回默 ...
-
在模拟类中保留注释以使用Reflection进行查找(Preserving Annotations in a mocked class for lookup using Reflection)[2022-02-12]
不幸的是不可能。 Mockito家伙正在使用CGLIB作为字节码引擎,他们使用它的方式不允许对方法(或其他任何事情)进行注释注入,所以不幸的是,Mockito无法实现你想做的事情。 我认为他们的跟踪器中存在一些关于相关事情的错误/增强。 为了克服这一点 - 你可以创造自己的间谍,而不是使用Mockito的间谍吗? 就像创建一个扩展你现在正在监视的类的类,并以某种方式覆盖会导致测试出现问题的东西? 很难给出更具体的建议,无需看到课程本身。 Unfortunately not possible. Mockito ... -
一种方法: public class YourTest { @Order public static class YourAnnotatedClass extends YourClass {} @Mock YourAnnotatedClass yourAnnotatedClass; // ... } 这将确保您的类型在其层次结构中具有所需的注释。 Mockito的覆盖基于Proxy / CGLIB / ByteBuddy,并不完全在任何适当的类上进行注释或在反射中使用。 实际上,可能有一些 ...
-
Mockito在通过时没有认出我的模拟类()(Mockito not recognizing my mocked class when passing through when())[2023-09-28]
你不要覆盖你的模拟 mockCrypto = CryptoManager.getCrypto(); 经测试 @Test(expected=RuntimeException.class) public void testdecrpyMcpDataExceptions() throws Exception { Crypto mockCrypto = mock(Crypto.class); doThrow(new RuntimeException()).when(moc ... -
你的代码不是测试友好的,特别是这两行测试非常糟糕: EntityDao entityDao = new EntityDao(); UserDao userDao = new UserDao(); 此代码应从此方法移至Factory或使用类似Spring(依赖注入)的类似注入。 仅靠Mockito无法测试这样的代码。 你的方法应该只做一件事,创建Daos是其他工作。 我会推荐你两部来自GoogleTechTalks的电影: 如何编写干净,可测试的代码 清洁代码会谈 - 不要寻找东西! Your code i ...
-
@ kerseyd27, 从您的测试名称testThatObjectsAreNullifiedInOnDestroy看来,您希望验证在演示者被销毁时,您的演示者是否释放了注入的mFooBar对象。 首先,直接回答你的问题: 与我实例化运行测试的对象相比,我的测试类中的模拟对象如何处理引用? 我会让这些答案( 链接1 , 链接2 )说明一切,但解释它与您的问题有何关系。 模拟对象在Test类中实例化,并通过值传递到FooPresenter 。 FooPresenter.mFooBar是FooPresenter ...