java - Junit test function which returns a string -
i have function inside class :
public string coverttolowercase(string slicename) { slicename = slicename.trim().tolowercase(); slicename = slicename.replaceall("\\.txt$|\\.dat$", ""); return slicename; }
i want test using junit. have created separate test file has following:
public class mycontrollertest { private mycontroller mycontroller; private static final string slice_name = "hello world"; @test public void shouldreturnsanitizedstring() throws exception { string expected = mycontroller.coverttolowercase(slice_name); // assert actual , expected same }
i not able understand how test , other examples specific functions. want function return sanitized string? how can go this?
you want test, first have prepare data test, input value, expected value => call test function input value => actual value return function under test => assert expected value actual value. here list of assert function can use.
public class mycontrollertest { private mycontroller mycontroller; private final string slice_name = "hello world"; private final string expected = "hello world"; @test public void shouldreturnsanitizedstring() throws exception { string actual = mycontroller.coverttolowercase(slice_name); // assert actual , expected same assertequals(expected, actual); } }
Comments
Post a Comment