Code example for TestCase

Methods: getClass, getName

0
			TestCase testCase = (TestCase) test;
			if (DataDrivenTestCase.class.isAssignableFrom(test.getClass())) {
				testName = ((DataDrivenTestCase) testCase).getCustomTestName();
			} else { 
 
				testName = testCase.getName();
			} 
		} 
		return testName;
	} 
 
	private boolean deleteDir(File dir) {
		if (dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDir(new File(dir, children[i]));
				if (!success) {
					return false; 
				} 
			} 
		} 
 
		// The directory is now empty so delete it 
		return dir.delete();
	} 
 
	private void openIfRequired() throws IOException { 
		String state = Environment.getExternalStorageState();
		if (mSerializer == null) {
			String fileName = mReportFile;
			if (mMultiFile) {
				fileName = fileName.replace("$(suite)", "test");
			} 
			if (mReportDir == null) {
				if (Environment.MEDIA_MOUNTED.equals(state)
						&& !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)&&checkWriteExternalPermission()) {
					File f = mContext.getExternalFilesDir("testng");
					mOutputStream = new FileOutputStream(new File(f, fileName));
				} else { 
					mOutputStream = mTargetContext.openFileOutput(fileName, 0);
				} 
			} else { 
				mOutputStream = new FileOutputStream(new File(mReportDir,
						fileName));
			} 
 
			mSerializer = Xml.newSerializer();
			mSerializer.setOutput(mOutputStream, ENCODING_UTF_8);
			mSerializer.startDocument(ENCODING_UTF_8, true);
			if (!mMultiFile) {
				mSerializer.startTag("", TAG_SUITES);
			} 
		} 
	} 
 
	@Override 
	public void addError(Test test, Throwable error) {
		errorCount++;
		addProblem(test, TAG_ERROR, error);
	} 
 
	@Override 
	public void addFailure(Test test, AssertionFailedError error) {
		failureCount++;
		addProblem(test, TAG_FAILURE, error);
	} 
 
	private void addProblem(Test test, String tag, Throwable error) {
		recordTestTime(test);
		TestKeeper testKeeper = getTestKeeper(test);
		testKeeper.setError(error);
		testKeeper.setTag(tag);
		if(TAG_ERROR.contentEquals(tag)){
			testKeeper.setStatus("SKIP");
		}else{ 
			testKeeper.setStatus("FAIL");
		} 
		addToSuite(test, testKeeper);
		updateSuiteDetails(test, tag);
	} 
 
	private TestKeeper getTestKeeper(Test test) {
		TestCase testcase = (TestCase) test;
		String suiteName = testcase.getClass().getName();
		HashMap<String, TestKeeper> suiteTests;
		if (suiteMap.containsKey(suiteName)) {
			suiteTests = suiteMap.get(suiteName);
			if (suiteTests.containsKey(getTestName(test))) {
				return suiteTests.get(getTestName(test));
			} 
		} 
		TestKeeper testKeeper = new TestKeeper();
		String testName = getTestName(test);
		testKeeper.setTestname(testName);
		mTestStartTime = System.currentTimeMillis();
		testKeeper.setStartTime(mTestStartTime);
		testKeeper.setTest(testcase);
		return testKeeper;
	} 
 
	private void recordTestTime(Test test) {
		if (!mTimeAlreadyWritten) {