????Java?????????д
???????????? ???????[ 2016/12/13 11:25:20 ] ??????????????? Java
????TestNG
??????????testng.xml??????TestNG?????????????????????????в?????????
<xml version="1.0" encoding="UTF-8"?>
<suite name="ParameterExampleSuite" parallel="false">
<test name="MathCheckerTest">
<classes>
<parameter name="num" value="3"></parameter>
<class name="com.stormpath.demo.MathCheckerTest"/>
</classes>
</test>
<test name="MathCheckerTest1">
<classes>
<parameter name="num" value="7"></parameter>
<class name="com.stormpath.demo.MathCheckerTest"/>
</classes>
</test>
</suite>
???????????????????????£????????????Σ??3??7????Ρ????????XML??????????????????????????????DataProvider????????????????????
????JUnit
??????TestNG??????????????????????????JUnit?????????????????MathChecker???JUnit??????????
@RunWith(Parameterized.class)
public class MathCheckerTest {
private int inputNumber;
private Boolean expected;
private MathChecker mathChecker;
@Before
public void setup(){
mathChecker = new MathChecker();
}
// Inject via constructor
public MathCheckerTest(int inputNumber?? Boolean expected) {
this.inputNumber = inputNumber;
this.expected = expected;
}
@Parameterized.Parameters
public static Collection<Object[]> getTestData() {
return Arrays.asList(new Object[][]{
{1?? true}??
{2?? false}??
{3?? true}??
{4?? false}??
{5?? true}
});
}
@Test
public void testisOdd() {
System.out.println("Running test for:"+inputNumber);
assertEquals(mathChecker.isOdd(inputNumber)?? expected);
}
}
????????????????????в?????????????getTestData??????????????????????????????????????????????????????????????
????5.???????????Print???
??????????????????????????д???????дSystem.out.println????????????????????С????????????????????????????????2??????????????????????????????????????????????????????????????????????????С???????????????????????????????
????????? StringUti ????????????????????????????????????????????????
????public class StringUtil {
????public String concat(String a??String b) {
????return a + b;
????}
????}
????????????????????????????????
@Test
public void testStringUtil_Bad() {
String result = stringUtil.concat("Hello "?? "World");
System.out.println("Result is "+result);
}
@Test
public void testStringUtil_Good() {
String result = stringUtil.concat("Hello "?? "World");
assertEquals("Hello World"?? result);
}
????testStringUtil\_Bad????????????????ж?????????????????????????????????????????????????????????????????????????????testStringUtil\_Good??????
????6.????????????????????
?????Щ??????????????????????÷????????????????????????????ζ??????????磬???????′?????????????????????????????и?????????????????????λ?????????
public class DemoLogic {
private void veryComplexFunction(){
//This is a complex function that has a lot of database access and is time consuming
//To demo this method?? I am going to add a Thread.sleep for a random number of milliseconds
try {
int time = (int) (Math.random()*100);
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public long calculateTime(){
long time = 0;
long before = System.currentTimeMillis();
veryComplexFunction();
long after = System.currentTimeMillis();
time = after - before;
return time;
}
}
??????????????£??????? calculateTime ????????????????????????????÷?????д???????????????κ??????????÷???????????????????????????????????κ??????е??????
????7.???????????????????????????????
??????????????????????????????????д?????????????????ó??????????????????????????????????????????????????????????????????????Ч?????????????????磬???????????????????????????8????????????????????????????????????????????????????????
?????????????????????????????????
???????????????
???????????????С??8??????????
????????????????????????????????????????????磬??????????????1??100???????????1??100???????????Щ????в???????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????