public class TestBuilder extends Object
BehaviorTester. See the
JavaDoc on that class for an example.
Automatically imports Assert.* and Truth.assertThat(T).
Does some ugly things to get meaningful file names and line numbers in the generated source. If you invoke build() directly from your test method, the generated class name and method name should line up with your test. Additionally, if you invoke addLine() directly from your test method, without loops, the line numbers should line up with your test in Eclipse. (Specifically, if you invoke addLine with line numbers that increase monotonically, and do not include extra newlines in your code strings, then the test builder will be able to generate a source file with those lines at the same line numbers.) Sadly, javac does not appear to produce such specific line numbers when faced with a fluent API.
Note that there is no incorrect way to use the class; you will just find compiler error messages and assertion stack traces are more useful when your test code is simple.
| Constructor and Description |
|---|
TestBuilder() |
| Modifier and Type | Method and Description |
|---|---|
TestBuilder |
addImport(Class<?> cls) |
TestBuilder |
addImport(String cls) |
TestBuilder |
addLine(String fmt,
Object... args)
Appends a formatted line of code to the source.
|
TestBuilder |
addStaticImport(Class<?> cls,
String method) |
TestBuilder |
addStaticImport(String cls,
String method) |
JavaFileObject |
build()
Returns a
JavaFileObject for the test source added to the builder. |
public TestBuilder addStaticImport(Class<?> cls, String method)
public TestBuilder addStaticImport(String cls, String method)
public TestBuilder addImport(Class<?> cls)
public TestBuilder addImport(String cls)
public TestBuilder addLine(String fmt, Object... args)
String.format(java.lang.String, java.lang.Object...),
except that Class instances use their entity's name unadorned, rather than the usual
toString implementation.public JavaFileObject build()
JavaFileObject for the test source added to the builder.Copyright © 2015 inferred.org. All rights reserved.