Last active
December 11, 2015 18:29
-
-
Save sue445/4641958 to your computer and use it in GitHub Desktop.
ExternalResourceでテストコードのリファクタリングをしてみるサンプル
This file contains 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.After; | |
import org.junit.Before; | |
public abstract class BaseTest { | |
@Before | |
public void setUp() throws Exception { | |
// setup | |
} | |
@After | |
public void tearDown() throws Exception { | |
// teardown | |
} | |
} |
This file contains 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.rules.ExternalResource; | |
public class BaseTestResource extends ExternalResource{ | |
@Override | |
protected void before() throws Throwable { | |
// setup | |
} | |
@Override | |
protected void after() { | |
// teardown | |
} | |
} |
This file contains 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
public class BaseTestResource extends ExternalResource{ | |
@Override | |
protected void before() throws Throwable { | |
// setup | |
} | |
@Override | |
protected void after() { | |
// teardown | |
} | |
public String getPath(){ | |
return ""; | |
} | |
public HttpServletRequest request; | |
} |
This file contains 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.Test; | |
public class SampleTest { | |
@Test | |
public void someTest() throws Exception { | |
// setup | |
// exercise | |
// verify | |
// teardown | |
} | |
} |
This file contains 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.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class SampleTest { | |
@Before | |
public void setUp() throws Exception { | |
// setup | |
} | |
@After | |
public void tearDown() throws Exception { | |
// teardown | |
} | |
@Test | |
public void someTest() throws Exception { | |
// exercise | |
// verify | |
} | |
} |
This file contains 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.Test; | |
public class SampleTest extends BaseTest{ | |
@Test | |
public void someTest() throws Exception { | |
// exercise | |
// verify | |
} | |
} |
This file contains 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; | |
public class SampleTest{ | |
@Rule | |
public BaseTestResource resource = new BaseTestResource(); | |
@Test | |
public void someTest() throws Exception { | |
// exercise | |
// verify | |
} | |
} |
This file contains 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.Test; | |
public class SampleTest extends BaseTest{ | |
@Test | |
public void someTest() throws Exception { | |
// exercise | |
String path = super.getPath(); | |
HttpServletRequest request = super.request; | |
// verify | |
} | |
} |
This file contains 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
public class SampleTest{ | |
@Rule | |
public BaseTestResource resource = new BaseTestResource(); | |
@Test | |
public void someTest() throws Exception { | |
// exercise | |
String path = resource.getPath(); | |
HttpServletRequest request = resource.request; | |
// verify | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment