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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -