나는 하나의 testclass를 가진이 robotium testproject를 가지고있다. 테스트 클래스는 모든 테스트 메소드를 포함합니다. 지금 테스트 클래스를 실행할 때, 테스트 메소드는 알파벳 순서로 실행됩니다. 테스트 메소드간에 몇 가지 종속성이 있으므로 (나는 이것이 바람직한 방법이 아니라는 것을 알고있다.) 테스트 메소드가 특정 순서로 실행되기를 바란다. 의존성을 갖는 이유는 적은 코드를 작성하고 전체 테스트 클래스를 더 빠르게 실행할 수 있기 때문입니다. 테스트 방법을 특정 순서로 실행하는 방법이 있습니까?특정 순서로 로봇 테스트를 실행하는 방법은 무엇입니까?
2
A
답변
1
특정 순서로 실행되도록하는 방법은 각 테스트 사례에 대해 개체를 만든 다음 각 테스트 사례 중 하나에서 각 개체를 인스턴스화하는 것입니다. 이를 통해 언제 어떤 테스트가 실행되는지 확인할 수 있습니다. 단점은 설치 방법을 한 번만 실행한다는 것입니다. 여기
내가 무슨 짓을 : 여기에 설명 된대로
...//class variables and such
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public NewRobotiumTest() throws ClassNotFoundException {
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
to = new TestObject();
/*This resets the test documents.
* If running multiple test methods in this class
* remove this method from the setup and place in first test method*/
to.restTestDocuments();
}
public void testSuite() throws IOException {
try {
// Test the Recommended For You section
RecommendForYou rfy = new RecommendForYou();
rfy.testRecommedForYou(solo, to);
Log.i(TAG, RECOMMENDED + " Section test complete.");
//Test the Music section of the app
Music music = new Music();
music.testMusic(solo, to);
Log.i(TAG, MUSIC + " Section test complete.");
// Test Social Networking section of the app
Social social = new Social();
social.testSocial(solo, to);
Log.i(TAG, SOCIAL + " Section test complete.");
// Test Verizon Apps section of the app
VerizonApps vza = new VerizonApps();
vza.testVerizonApps(solo, to);
Log.i(TAG, VERIZONAPPS + " Section test complete.");
// Test Entertainment section of the app
Entertainment ent = new Entertainment();
ent.testEntertainment(solo, to);
Log.i(TAG, ENTERTAINMENT + " Section test complete.");
// Test Games Section of the app
Games games = new Games();
games.testGames(solo, to);
Log.i(TAG, GAMES + " Section test complete.");
// Test Featured section of the app
Featured featured = new Featured();
featured.testFeatured(solo, to);
Log.i(TAG, FEATURED + " Section test complete.");
// Test Business section of catalog
Business bus = new Business();
bus.testBusiness(solo, to);
Log.i(TAG, BUSINESS + " Section test complete.");
// Test the New Apps link in the ODP catalog
NewApps nat = new NewApps();
nat.testNewApps(solo, to);
Log.i(TAG, NEW + " Section test complete.");
//Test the Top Sellers section of the app
TopSeller ts = new TopSeller();
ts.testTopSellers(solo, to);
Log.i(TAG, TOPSELLER + " Section test complete.");
//Test the Top Download section of the app
TopDownload td = new TopDownload();
td.testTopDownload(solo, to);
Log.i(TAG, TOPDOWNLOAD + " Section test complete.");
//Test the Themes section of the app
Themes themes = new Themes();
themes.testThemes(solo, to);
Log.i(TAG, THEMES + " Section test complete.");
//Test the Tools section of the app
Tools tools = new Tools();
tools.testTools(solo, to);
Log.i(TAG, TOOLS + " Section test complete.");
//Test the News section of the app
News news = new News();
news.testNews(solo, to);
Log.i(TAG, NEWS + " Section test complete.");
//Test the Sports section of the app
Sports sports = new Sports();
sports.testSports(solo, to);
Log.i(TAG, SPORTS + " Section test complete.");
//Test the Reading section of the app
Reading read = new Reading();
read.testReading(solo, to);
Log.i(TAG, READING + " Section test complete.");
//Test the Money section of the app
Money money = new Money();
money.testMoney(solo, to);
Log.i(TAG, MONEY + " Section test complete.");
//Test the Shopping section of the app
Shopping shop = new Shopping();
shop.testShopping(solo, to);
Log.i(TAG, SHOPPING + " Section test complete.");
//Test the Fitness section of the app
Fitness fit = new Fitness();
fit.testFitness(solo, to);
Log.i(TAG, FITNESS + " Section test complete.");
//Test the Travel Section of the app
Travel travel = new Travel();
travel.testTravel(solo, to);
Log.i(TAG, TRAVEL + " Section test complete.");
//Test the Spanish section of the app
Spanish spanish = new Spanish();
spanish.testSpanish(solo, to);
Log.i(TAG, SPANISH + " Section test complete.");
// Test the search functionality
TestSearch test = new TestSearch();
test.testSearchFunctionality(solo, to);
} catch (Exception e) {
e.printStackTrace();
} finally {
printTotals(to);
}
}
@Override
public void tearDown() throws Exception {
try {
bw.close();
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
solo.finishOpenedActivities();
super.tearDown();
}
public void printTotals(TestObject to) throws IOException {
// if there is no SD card
if (Environment.getExternalStorageState() == null) {
directory = new File(Environment.getDataDirectory()
+ "/RobotiumTestLog/");
photoDirectory = new File(Environment.getDataDirectory()
+ "/Robotium-Screenshots/");
// if no directory exists, create new directory
if (!directory.exists()) {
directory.mkdir();
}
// if phone DOES have sd card
} else if (Environment.getExternalStorageState() != null) {
// search for directory on SD card
directory = new File(Environment.getExternalStorageDirectory()
+ "/RobotiumTestLog/");
photoDirectory = new File(Environment.getExternalStorageDirectory()
+ "/Robotium-Screenshots/");
// if no directory exists, create new directory to store test
// results
if (!directory.exists()) {
directory.mkdir();
}
}// end of SD card checking
String fileName2 = "TotalTestResults.csv";
File totLogRes = new File(directory, fileName2);
bw = new BufferedWriter(new FileWriter(totLogRes, true));
int totCases = to.getTestCase();
int totPass = to.getTestPass();
int totFail = to.getTestFail();
int totRev = to.getNeedReview();
bw.write("\"\n\"");
bw.write("Total Test Results\",\"" + totCases + "\",\"" + totPass
+ "\",\"" + totFail + "\",\"" + totRev + "\"\n\"");
}
}
0
당신은 단지 테스트를 구성 할 JUnit을 권장 사항을 따르도록 시도 할 수 있습니다 : http://etutorials.org/Programming/Java+extreme+programming/Chapter+4.+JUnit/4.8+Organizing+Tests+into+Test+Suites/
3
이 testsuit의 순서를 포함하는 클래스를 만듭니다. 예를 들어 :
package com.android.test;
import junit.framework.TestSuite;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
public class AllTests extends ActivityInstrumentationTestCase2<Activity> {
public AllTests(Class<Activity> activityClass) {
super(activityClass);
}
public static TestSuite suite() {
TestSuite t = new TestSuite();
t.addTestSuite(SplashScreenTest.class);
t.addTestSuite(MainLoginScreenTest.class);
t.addTestSuite(EmailSignUpScreenTest.class);
t.addTestSuite(EmailVerificationTest.class);
t.addTestSuite(EmailLoginScreenTest.class);
return t;
}
@Override
public void setUp() throws Exception {
}
@Override
public void tearDown() throws Exception {
}
}
이 방법으로 당신은 당신의 robotium 테스트 슈트의 실행 순서를 설정할 수 있습니다. 튜토리얼을 확인하려면 link