Created
September 23, 2019 18:45
-
-
Save sauceaaron/bbc29f4ee16bc1ee459988fb2098e9ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.junit.Rule; | |
| import org.junit.Test; | |
| import org.junit.rules.TestName; | |
| import static org.junit.Assert.assertEquals; | |
| public class TestDataFromName | |
| { | |
| @Rule | |
| public TestName testName = new TestName(); | |
| @Test | |
| public void testHello_Aaron() | |
| { | |
| // use TestName Rule to get the current method name | |
| String methodName = testName.getMethodName(); | |
| // get everything after the underscore | |
| String parameter = methodName.substring(methodName.indexOf("_")+1); | |
| // execute code to test | |
| String result = greeting(parameter); | |
| // check result | |
| assertEquals(result, "Hello, Aaron"); | |
| } | |
| public String greeting(String name) { | |
| if (name == null) | |
| { | |
| name = "World"; | |
| } | |
| return "Hello, " + name; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment