java - testing regular expression using junit? -
i have written regular expression ignore space: regular expression
string ignore_regx = "[^\\s]"; testcase: public void testclass { @test public void testignoreregx() { string input = " hai"; asserttrue(input.matches(ignore_regx)); } }
but above test failing.
could body please how test above expression using junit?
consider using theories test multiple values.
@runwith(theories.class) public void testclass { @datapoints public static final string[] truevalues = new string[]{"", "blah", ...}; @datapoints public static final string[] falsevalues = new string[]{" ", " blah", "glah "}; @theory public void testignoreregx_true(string input) { assume.assumethat(input, isin.isin(truevalues)); asserttrue(input.matches(ignore_regx)); } @theory public void testignoreregx_false(string input) { assume.assumethat(input, isin.isin(falsevalues )); assertfalse(input.matches(ignore_regx)); } }
Comments
Post a Comment