Skip to content

Commit 59d5a67

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 59d5a67

File tree

5 files changed

+848
-0
lines changed

5 files changed

+848
-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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2013-2023 Real Logic Limited.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package uk.co.real_logic.sbe.properties;
18+
19+
import net.jqwik.api.Arbitrary;
20+
import net.jqwik.api.ForAll;
21+
import net.jqwik.api.Property;
22+
import net.jqwik.api.Provide;
23+
import uk.co.real_logic.sbe.xml.ParserOptions;
24+
25+
import java.io.ByteArrayInputStream;
26+
import java.io.InputStream;
27+
import java.nio.charset.StandardCharsets;
28+
29+
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.parse;
30+
31+
public class ParserPropertyTest
32+
{
33+
@Property
34+
void shouldParseAnyValidSchema(@ForAll("schemas") final SchemaDomain.MessageSchema schema) throws Exception
35+
{
36+
final String xml = XmlSchemaWriter.writeString(schema);
37+
try (InputStream in = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
38+
{
39+
parse(in, ParserOptions.DEFAULT);
40+
}
41+
}
42+
43+
@Provide
44+
Arbitrary<SchemaDomain.MessageSchema> schemas()
45+
{
46+
return SchemaDomain.MessageSchema.arbitrary();
47+
}
48+
}

0 commit comments

Comments
 (0)