Code example for TestCase

Methods: getClass, getName

0
			testKeeper.setTestname(testName);
			mTimeAlreadyWritten = false;
			mTestStartTime = System.currentTimeMillis();
			testKeeper.setStartTime(mTestStartTime);
			currentSuite.setStartTime(System.currentTimeMillis());
			testKeeper.setTest(testCase);
			checkSuiteDetails(test);
			addToSuite(test, testKeeper);
		} 
	} 
 
	private void addToSuite(Test test, TestKeeper testKeeper) {
		TestCase testcase = (TestCase) test;
		String suiteName = testcase.getClass().getName();
		HashMap<String, TestKeeper> suiteTests;
		if (suiteMap.containsKey(suiteName)) {
			suiteTests = suiteMap.get(suiteName);
		} else { 
			suiteTests = new HashMap<String, TestKeeper>();
		} 
		if (suiteDetails.containsKey(suiteName)) {
			SuiteKeeper sKeeper = suiteDetails.get(suiteName);
			currentSuite.setEndTime(sKeeper.getEndTime());
			sKeeper.setEndTime(testKeeper.getEndTime());
			suiteDetails.put(suiteName, sKeeper);
		} 
		suiteTests.put(getTestName(test), testKeeper);
		suiteMap.put(suiteName, suiteTests);
	} 
 
	private void checkSuiteDetails(Test test) {
		TestCase testcase = (TestCase) test;
		String suiteName = testcase.getClass().getName();
		if (!suiteDetails.containsKey(suiteName)) {
			SuiteKeeper sKeeper = new SuiteKeeper();
			sKeeper.setStartTime(System.currentTimeMillis());
			suiteDetails.put(suiteName, sKeeper);
		} 
	} 
 
	private void updateSuiteDetails(Test test, String tag) {
		checkSuiteDetails(test);
		TestCase testcase = (TestCase) test;
		String suiteName = testcase.getClass().getName();
		SuiteKeeper suiteKeeper = suiteDetails.get(suiteName);
		if (tag.contentEquals(TAG_ERROR)) {
			suiteKeeper.setErrorCount();
		} else if (tag.contentEquals(TAG_FAILURE)) {
			suiteKeeper.setFailureCount();
		} 
	} 
 
	private String getTestName(Test test) {
		String testName = "";
		if (test instanceof TestCase) {
			TestCase testCase = (TestCase) test;
			if (DataDrivenTestCase.class.isAssignableFrom(test.getClass())) {
				testName = ((DataDrivenTestCase) testCase).getCustomTestName();
			} else { 
 
				testName = testCase.getName();
			} 
		} 
		return testName;
	}