我build.gradle有:
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0'
Run Code Online (Sandbox Code Playgroud)
使用http://junit.org/junit5/docs/current/user-guide/中的标准示例
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class FirstJUnit5Tests {
@Test
void myFirstTest() {
assertEquals(2, 1 + 1);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在IntelliJ 2017.2.3中作为JUnit测试运行时,我得到:
objc[32347]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f5be4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f6864e0). One of the two will be used. Which one is undefined.
Sep 11, 2017 12:39:04 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'junit-jupiter' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ClassUtils.isKotlinClass(Ljava/lang/Class;)Z
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$getTestInstanceLifecycle$14(ClassTestDescriptor.java:299)
at java.util.Optional.orElseGet(Optional.java:267)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.getTestInstanceLifecycle(ClassTestDescriptor.java:299)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.<init>(ClassTestDescriptor.java:87)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.<init>(ClassTestDescriptor.java:77)
at …Run Code Online (Sandbox Code Playgroud) 我试图在Jupiter上网本上运行tensorflow,python 2.7但我意识到它需要3.6 pythong版本所以我按照这个步骤:
使用Anaconda安装
通过调用以下命令创建名为tensorflow的conda环境:
C:> conda create -n tensorflow pip python=3.5
Run Code Online (Sandbox Code Playgroud)
通过发出以下命令激活conda环境:
C:> activate tensorflow
Run Code Online (Sandbox Code Playgroud)
(tensorflow)C:>#您的提示应该更改发出适当的命令在您的conda环境中安装TensorFlow.要安装仅CPU版本的TensorFlow,请输入以下命令:
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Run Code Online (Sandbox Code Playgroud)
要安装TensorFlow的GPU版本,请输入以下命令(在一行上):
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
Run Code Online (Sandbox Code Playgroud)
**
**
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Run Code Online (Sandbox Code Playgroud)
告诉我这个错误:
由于EnvironmentError导致无法安装软件包:[WinError 5]访问被拒绝:'C:\ Users\idan\AppData\Local\Continuum\anaconda2\envs\tensorflow\Lib\site-packages \numpy\.libs\libopenblas. BNVRK7633HSX7YVO2TADGR4A5KEKXJAW.gfortran-win_amd64.dll'考虑使用该
--user选项或检查权限.
我试图更改用户权限,并以管理员身份打开anaconda cmd但它没有帮助.
我有一个示例测试类,我想在其中模拟一个静态类。我的 build.gradle 就像
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.2.0'
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'
testRuntime("org.junit.platform:junit-platform-launcher:1.1.1")
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0'
testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.21.0'`
Run Code Online (Sandbox Code Playgroud)
当我尝试我的测试用例时
@ExtendWith(MockitoExtension.class)
@PrepareForTest(MyUtil.class)
public class MyTest {
@Test
public void shouldCheckIfSyncTimeIsAboveThreshold() {
mockStatic(MyUtil.class);
when(MyUtil.getValue()).thenReturn(5));
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个时,我得到了像
org.powermock.api.mockito.ClassNotPreparedException:
The class MyUtil not prepared for test
Run Code Online (Sandbox Code Playgroud)
有什么办法可以让我达到同样的目标
import groovy.transform.CompileStatic
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
import static org.assertj.core.api.Assertions.assertThat
@CompileStatic
class MyUnitTest {
@ParameterizedTest(name = "{index} => myString={0}")
@MethodSource("provideData")
void test(String myString) {
assertThat("hallo").isEqualTo(myString)
}
private static Stream<Arguments> provideData() {
return Stream.of(
Arguments.of("hallo"))
}
}
Run Code Online (Sandbox Code Playgroud)
运行这个 JUnit 5 测试给了我以下错误:方法
org.junit.jupiter.params.provider.Arguments.of([Ljava/lang/Object;)Lorg/junit/jupiter/params/provider/Arguments; 必须是 InterfaceMethodref 常量 java.lang.IncompatibleClassChangeError: Method org.junit.jupiter.params.provider.Arguments.of([Ljava/lang/Object;)Lorg/junit/jupiter/params/provider/Arguments; 必须是 InterfaceMethodref 常量
我使用 Java 10,并且在 build.gradle 中启用了 JUnit 5。
我定义了自己的 JUnit 注释:
@ParameterizedTest
@MethodSource("myorg.qa.ccrtesting.DataProviders#standardDataProvider")
@Tags({@Tag("ccr"), @Tag("standard")})
public @interface CcrStandardTest {
}
Run Code Online (Sandbox Code Playgroud)
然后,我可以在测试中使用该注释:
@CcrStandardTest
public void E0010_contact_standard (String testData) {
...
Run Code Online (Sandbox Code Playgroud)
-eamyorg.qa.ccrtesting.ccrstandardtests.CcrStanConTest- 这是 IDE 建议的(并经过验证指向正确的类,其中包含我的原型测试方法)然而,这会导致:jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [java.lang.String arg0] in method [public void...
我尝试String testData从测试方法签名中删除,但 JUnit 没有执行任何测试:No tests found
当我在@Test原型测试方法上方添加时,它会执行但是:
@CcrStandardTest被应用suspicious combination @Test and parameterized source @ParameterizedTestimply @Test,只是不确定为什么 IDE 能够找到自定义注释,而 JUnit 却不能?)(使用 OpenJDK-13 和 JUnit5-Jupiter)
问题是我的单元测试每个都使用了一个不小的 JUnit 注释系统,如下所示:
@ParameterizedTest
@MethodSource("myorg.ccrtest.testlogic.DataProviders#standardDataProvider")
@Tags({@Tag("ccr"), @Tag("standard")})
Run Code Online (Sandbox Code Playgroud)
这使得测试编写有点乏味,测试代码有点长,当然,当需要更改时,这是一件苦差事!
想知道我是否可以创建自己的 JUnit annotation: @CcrStandardTest,这意味着上面的所有注释?
我还尝试将类定义中的注释向上移动(希望它们随后适用于类的所有方法),但编译器说不:“@ParameterizedTest 不适用于类型”
junit5 ×5
java ×3
annotations ×2
junit ×2
reflection ×2
unit-testing ×2
anaconda ×1
groovy ×1
mockito ×1
powermock ×1
python-3.x ×1
tensorflow ×1