Apache Beam 似乎不是 运行 测试
Apache Beam seems to not be running the tests
我有一组在我的代码库上实施的测试,但似乎没有执行和通过。作为必然结果,Jacoco 代码覆盖不会报告这些测试的任何执行情况。这是问题的一个例子。
package com.striiv.dataflow;
import org.apache.beam.sdk.coders.AvroCoder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.PCollection;
import org.junit.Test;
public class SampleTest {
public final transient TestPipeline pipeline = TestPipeline.create();
public static <T> DoFn<T, T> print(String label) {
return new DoFn<T, T>() {
@ProcessElement
public void print(ProcessContext ctx) {
String message = ctx.element().toString();
System.out.println(message);
ctx.output(ctx.element());
}
};
}
@Test
public void testPrintFunctionDoesNotMutateData () {
Object genericObject = new Object();
PCollection<Object> collection = pipeline
.apply(Create.of(genericObject).withCoder(AvroCoder.of(Object.class)))
.apply(ParDo.of(print("Label")));
PAssert.that(collection).empty();
PAssert.that(collection).containsInAnyOrder(genericObject);
}
}
这个测试应该会失败,因为这两个断言相互矛盾。
我在这里错过了什么?
一些信息:
$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (IcedTea 3.16.0) (Gentoo icedtea-3.16.0)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>2.16.0</version>
</dependency>
要运行它,你必须运行它pipeline.run()
。将其添加到您的测试方法中,请重试。
@Test
public void testPrintFunctionDoesNotMutateData () {
Object genericObject = new Object();
PCollection<Object> collection = pipeline
.apply(Create.of(genericObject).withCoder(AvroCoder.of(Object.class)))
.apply(ParDo.of(print("Label")));
PAssert.that(collection).empty();
PAssert.that(collection).containsInAnyOrder(genericObject);
pipeline.run();
}
我有一组在我的代码库上实施的测试,但似乎没有执行和通过。作为必然结果,Jacoco 代码覆盖不会报告这些测试的任何执行情况。这是问题的一个例子。
package com.striiv.dataflow;
import org.apache.beam.sdk.coders.AvroCoder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.PCollection;
import org.junit.Test;
public class SampleTest {
public final transient TestPipeline pipeline = TestPipeline.create();
public static <T> DoFn<T, T> print(String label) {
return new DoFn<T, T>() {
@ProcessElement
public void print(ProcessContext ctx) {
String message = ctx.element().toString();
System.out.println(message);
ctx.output(ctx.element());
}
};
}
@Test
public void testPrintFunctionDoesNotMutateData () {
Object genericObject = new Object();
PCollection<Object> collection = pipeline
.apply(Create.of(genericObject).withCoder(AvroCoder.of(Object.class)))
.apply(ParDo.of(print("Label")));
PAssert.that(collection).empty();
PAssert.that(collection).containsInAnyOrder(genericObject);
}
}
这个测试应该会失败,因为这两个断言相互矛盾。 我在这里错过了什么?
一些信息:
$ java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (IcedTea 3.16.0) (Gentoo icedtea-3.16.0)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-sdks-java-core</artifactId>
<version>2.16.0</version>
</dependency>
要运行它,你必须运行它pipeline.run()
。将其添加到您的测试方法中,请重试。
@Test
public void testPrintFunctionDoesNotMutateData () {
Object genericObject = new Object();
PCollection<Object> collection = pipeline
.apply(Create.of(genericObject).withCoder(AvroCoder.of(Object.class)))
.apply(ParDo.of(print("Label")));
PAssert.that(collection).empty();
PAssert.that(collection).containsInAnyOrder(genericObject);
pipeline.run();
}