File tree Expand file tree Collapse file tree 3 files changed +61
-4
lines changed Expand file tree Collapse file tree 3 files changed +61
-4
lines changed Original file line number Diff line number Diff line change 5
5
6
6
[lib ]
7
7
8
- [dependencies ]
8
+ [dependencies ]
9
+
10
+ [dev-dependencies ]
11
+ proptest = " 0.7.1"
Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ revealOptions:
7
7
# Testing in Rust
8
8
9
9
* Language Feature
10
- * Specialized Libraries
11
- * e.g. for Property Testing
10
+ * Rust Testing Libraries
11
+ * e.g. proptest, netsim
12
12
* Language-agnostic tools
13
13
* e.g. Jepsen, TLA+
14
14
@@ -82,4 +82,46 @@ extern crate test;
82
82
83
83
* Based on Python's "Hypothesis" module
84
84
* Which in turn is based on Haskell's "QuickCheck"
85
- * By convention appended to the same file to be tested
85
+ * Randomly checks over an input range
86
+ * Automatically reduces to a * minimal* test case
87
+ * Writes seed for random number generation in case of failure
88
+ * Makes random failures repeatable
89
+ * Combine with traditional Unit Testing for edge cases
90
+
91
+ ----
92
+ ### Usage
93
+
94
+ * Import proptest crate with using_macros and test attributes
95
+ ```
96
+ #[cfg(test)]
97
+ #[macro_use]
98
+ extern crate proptest;
99
+ ```
100
+ * Then use the proptest! macro to define tests
101
+
102
+ ----
103
+
104
+ ### Example
105
+
106
+ ```
107
+ proptest! {
108
+ #[test]
109
+ fn a_proptest(a in (0i32..100),
110
+ b in (0i32..100)) {
111
+ assert!(a * b <= 10000);
112
+ }
113
+ }
114
+ ```
115
+
116
+ ----
117
+
118
+ ### String Patterns
119
+
120
+ * proptest supports more advanced range patterns
121
+ * patterns extensible as "Strategies"
122
+ ```
123
+ #[test]
124
+ fn parses_all_valid_dates(s in "[0-9]{4}-[0-9]{2}-[0-9]{2}") {
125
+ parse_date(s).unwrap();
126
+ }
127
+ ```
Original file line number Diff line number Diff line change 1
1
#![ feature( test) ]
2
2
extern crate test;
3
3
4
+ #[ cfg( test) ]
5
+ #[ macro_use]
6
+ extern crate proptest;
7
+
4
8
mod child_module;
5
9
6
10
pub fn a_public_function ( ) -> i32 {
@@ -27,4 +31,12 @@ mod tests {
27
31
fn a_benchmark ( b : & mut Bencher ) {
28
32
b. iter ( || a_public_function ( ) ) ;
29
33
}
34
+
35
+ proptest ! {
36
+ #[ test]
37
+ fn a_proptest( a in ( 0i32 ..100 ) ,
38
+ b in ( 0i32 ..100 ) ) {
39
+ assert!( a * b <= 10000 ) ;
40
+ }
41
+ }
30
42
}
You can’t perform that action at this time.
0 commit comments