raf*_*000 3 java testing gradle
我正在关注一个小测试脚本并为其提供第一段代码以使其变为绿色.代码是java,测试与java混在一起.Java是Mac OSX"El Capitan"上的版本"1.8.0_60".gradle是版本2.8.
使用后gradle build,显示的错误如下:
$ gradle build
:compileJava
/Users/rsalazar/exercism/java/etl/src/main/java/Etl.java:1: error: package com.google.common.collect does not exist
import com.google.common.collect.ImmutableMap;
^
/Users/rsalazar/exercism/java/etl/src/main/java/Etl.java:9: error: cannot find symbol
return ImmutableMap.of("a", 1);
^
symbol: variable ImmutableMap
location: class Etl
2 errors
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.597 secs
Run Code Online (Sandbox Code Playgroud)
这是build.gradle文件:
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:4.10"
testCompile "org.easytesting:fest-assert-core:2.0M10"
testCompile "com.google.guava:guava:16+"
}
Run Code Online (Sandbox Code Playgroud)
这是测试:( EtlTest.java)
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.fest.assertions.api.Assertions.assertThat;
public class EtlTest {
private final Etl etl = new Etl();
@Test
public void testTransformOneValue() {
Map<Integer, List<String>> old = ImmutableMap.of(1, Arrays.asList("A"));
Map<String, Integer> expected = ImmutableMap.of("a", 1);
assertThat(etl.transform(old)).isEqualTo(expected);
}
}
Run Code Online (Sandbox Code Playgroud)
这是测试中的代码:( Etl.java)
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class Etl {
public Map<String, Integer> transform(Map <Integer, List<String>> from) {
return ImmutableMap.of("a", 1);
}
}
Run Code Online (Sandbox Code Playgroud)
我不是在寻求测试通过的帮助.只是帮助用gradle编译测试.我很遗憾地说,在使用提供的错误消息进行编译时我遇到了困难.我在网上找不到任何帮助.非常感谢!
由于您还需要ImmutableMap编译源代码(不仅是测试源代码),还需要更改此行:
testCompile "com.google.guava:guava:16+"
Run Code Online (Sandbox Code Playgroud)
对此:
compile "com.google.guava:guava:16+"
Run Code Online (Sandbox Code Playgroud)
它将在编译时为源代码提供guava,从而解决问题.
| 归档时间: |
|
| 查看次数: |
6948 次 |
| 最近记录: |