Skip to content

Commit 9fb2b17

Browse files
committed
[Java] Start to introduce property based testing (PBT).
In this commit, I've: 1. Added a test dependency on JQwik. 2. Added a JQwik-based generator of arbitrary valid SBE message schemas. This generator exercises a lot of possibilities but not all. In particular, it is missing the generation of constants, min/max, and custom offsets. 3. Added a test that shows the parser parses any arbitrary SBE message schema. Why have I introduced PBT? My aim is to eventually test (an approximation of) the following property: ``` ∀ msgSchema ∈ PossibleMessageSchemas, ∀ bytes ∈ PossibleValidValues(msgSchema), DtoEncode(DtoDecode(bytes)) = bytes ``` I.e., that `DtoEncode` is the inverse of `DtoDecode` and that it preserves the information in an encoded message.
1 parent 2f657ed commit 9fb2b17

File tree

5 files changed

+823
-0
lines changed

5 files changed

+823
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,7 @@ rust/Cargo.lock
114114
.DS_Store
115115
/sbe-tool/src/main/golang/uk_co_real_logic_sbe_ir_generated/
116116

117+
# JQwik
118+
*.jqwik-database
119+
117120
/generated/

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def checkstyleVersion = '9.3'
5757
def hamcrestVersion = '2.2'
5858
def mockitoVersion = '4.11.0'
5959
def junitVersion = '5.10.0'
60+
def jqwikVersion = '1.8.0'
6061
def jmhVersion = '1.37'
6162
def agronaVersion = '1.19.2'
6263
def agronaVersionRange = '[1.19.2,2.0[' // allow any release >= 1.19.2 and < 2.0.0
@@ -248,6 +249,7 @@ project(':sbe-tool') {
248249
testImplementation files('build/classes/java/generated')
249250
testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
250251
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
252+
testImplementation "net.jqwik:jqwik:${jqwikVersion}"
251253
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
252254
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
253255
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package uk.co.real_logic.sbe.properties;
2+
3+
import net.jqwik.api.Arbitrary;
4+
import net.jqwik.api.ForAll;
5+
import net.jqwik.api.Property;
6+
import net.jqwik.api.Provide;
7+
import uk.co.real_logic.sbe.xml.ParserOptions;
8+
9+
import java.io.ByteArrayInputStream;
10+
import java.io.InputStream;
11+
import java.nio.charset.StandardCharsets;
12+
13+
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.parse;
14+
15+
public class ParserPropertyTest
16+
{
17+
@Property
18+
void shouldParseAnyValidSchema(@ForAll("schemas") final SchemaDomain.MessageSchema schema) throws Exception
19+
{
20+
final String xml = XmlSchemaWriter.writeString(schema);
21+
try (InputStream in = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
22+
{
23+
parse(in, ParserOptions.DEFAULT);
24+
}
25+
}
26+
27+
@Provide
28+
Arbitrary<SchemaDomain.MessageSchema> schemas()
29+
{
30+
return SchemaDomain.MessageSchema.arbitrary();
31+
}
32+
}

0 commit comments

Comments
 (0)