assertSame Junit testing

This is my method:

public static String passCheck(String x){
    return x; 
}

And here is my test for it:

Test
public void pass(){
    Testcases testcases = new Testcases();
    String y = "mypassword123";
    assertSame(y, testcases.passCheck(x)); 

}

How come there is an error saying variable x cannot be found?

Jon Skeet
people
quotationmark

How come there is an error saying variable x cannot be found?

Because x isn't declared in pass - it's only declared in passCheck. It's not in scope in your test method. This has nothing to do with JUnit - it's just plain Java.

You want:

assertSame(y, testcases.passCheck(y)); 

people

See more on this question at Stackoverflow