Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Just added the AbstractTestHarness Please use Eclipse, this program is in java, I need to create a simple class to display, Hello World from

Hello,

Just added the AbstractTestHarness

Please use Eclipse, this program is in java, I need to create a simple class to display, Hello World from my name. which I did, however, I got this error:

"

Validating Javadoc **

Running Week01 Javadoc Test

-- Running test: HelloWorld.java

******** Error processing HelloWorld.java ********

null

*****************************************************

Completed running Week01 Javadoc Test

** Test result: Failed **

FAILED

testJavadoc(week01.JUnitJavadocValidation)

- message:

- description: testJavadoc(week01.JUnitJavadocValidation)

- exception: java.lang.AssertionError:

-----------------------------------------------

-- Failed.

Could you please create that class and give me an explanation on why I got these errors.

bellow is the package for testing

Thank you.

package week01;

import static org.junit.Assert.*;

import java.io.PrintStream;

import java.util.ArrayList;

import java.util.List;

import org.junit.Test;

import test.TestResult;

import test.TestResultDetail;

import test.javadoc.FileTestData2;

import test.javadoc.JUnitJavadocValidationUtility2;

import test.javadoc.MethodTestData2;

/**

* Tests the Javadoc in the source file.

*

* @author Dina

*

*/

public class JUnitJavadocValidation

{

public JUnitJavadocValidation()

{

m_stream = System.out; // Standard out

List testFiles = new ArrayList();

List methods = new ArrayList();

methods.add(new MethodTestData2("display", "", "String","public"));

testFiles.add(new FileTestData2("week01", "HelloWorld.java", methods));

m_validator = new JUnitJavadocValidationUtility2("Week01 Javadoc Test",

testFiles);

m_validator.suppressParserTrace(false);

}

@Test

public void testJavadoc()

{

trace("** Validating Javadoc **");

// Update these values for each assignment

// m_packageName = "week02";

TestResult result = m_validator.runTest();

StringBuilder details = new StringBuilder();

if(!result.passed())

{

List detailList = result.getTestResultDetails();

for(TestResultDetail detail : detailList)

{

trace(detail.testDetails());

details.append(detail.testDetails());

details.append(CRLF);

}

}

trace(String.format("** Test result: %s **", result.passed() ? "Passed" : "Failed"));

assertTrue(details.toString(), result.passed());

}

/**

* Trace the msg to a PrintStream Provides the method for tests to report

* status

*

* @param msg

*/

private void trace(String msg)

{

m_stream.println(msg);

}

private JUnitJavadocValidationUtility2 m_validator;

protected PrintStream m_stream;

private static String CRLF = System.getProperty("line.separator");

}

/********************* test Harness**************/

package week01;

import test.AbstractTestHarness;

/**

* File: TestHarness.java

* @author Dina

*/

class TestHarness extends AbstractTestHarness

{

public static void main(String[] args)

{

new TestHarness().runTests();

}

/**

* Implements the baseclass abstract method

*/

protected void runTests()

{

try

{

boolean javadocTest = executeTest(JUnitJavadocValidation.class);

boolean helloWorldTest = executeTest(TestHelloWorld.class);

boolean result = javadocTest && helloWorldTest;

trace(result ? "Tests Passed" : "Tests Failed");

}

catch(Exception ex)

{

trace(ex.getMessage());

}

}

}

/****************************HelloWorldTest**************/

package week01;

import static org.junit.Assert.*;

import org.junit.Test;

public class TestHelloWorld

{

/**

* Default constructor

*/

public TestHelloWorld()

{

}

@Test

public void runTest()

{

boolean result = true;

HelloWorld hello = new HelloWorld();

String msg = hello.display();

// trace("Results from executing display() method: ");

// trace(" ");

if(msg.length() > 1 && msg.contains("Hello World from"))

{

result = true;

}

else

{

result = false;

//trace("Message doesn't match requirements - expected Hello World from ");

}

assertTrue("Message doesn't match requirements - expected Hello World from ", result);

}

static private void trace(String msg)

{

System.out.println(msg);

}

}

/************AbstractTestHarness**********************/

package test;

import java.util.List;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

/**

* Provides common services to the TestHarness instances

* @author Dina

*

*/

public abstract class AbstractTestHarness

{

/**

* Must be implemented by the subclass

*/

protected abstract void runTests();

protected boolean executeTest(@SuppressWarnings("rawtypes") Class c)

{

//trace("");

trace("===============================================");

trace(" -- executing " + c.getName());

trace("===============================================");

trace("");

boolean success = true;

Result result = org.junit.runner.JUnitCore

.runClasses(c);

int failCount = result.getFailureCount();

if(failCount > 0)

{

List failures = result.getFailures();

trace("FAILED");

for(Failure fail : failures)

{

trace(fail.getTestHeader());

trace(" - message: " + fail.getMessage());

trace(" - description: " + fail.getDescription());

trace(" - exception: " + fail.getException());

success = false;

}

}

trace("-----------------------------------------------");

trace(" -- " + (success ? "Success" : "Failed"));

trace("===============================================");

trace("");

return success;

}

static protected void trace(String msg)

{

System.out.println(msg);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago