Results 1 to 1 of 1
- 11-21-2010, 04:30 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 40
- Rep Power
- 0
junit.framework.AssertionFailedError:
Guys, I am getting this error when i tries to run a test on my project. The project is working fine, but the test for an authentication class fails.
This is the error I am getting:
this is my test classJava Code:junit.framework.AssertionFailedError: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at junit.framework.Assert.fail(Assert.java:47) at manager.LoginMgrTest.testValidLogin(LoginMgrTest.java:21)
the test worked fine last week and then I implemented a factory for creating services and stuff, now the test has to go get the particular services from the factory and return it to run the test. But as i said, the project is working fine(getting service from factory is ok for the project but not for the test).Java Code:package manager; import junit.framework.TestCase; import domain.*; public class LoginMgrTest extends TestCase { public void testValidLogin() throws Exception { System.out.println("starting testValidLogin()"); LoginBean login = new LoginBean(); login.setUsername("john"); login.setPassword("smith"); try{ CustomerBean cust = (new LoginMgr()).authenticate(login); assertNotNull("authenticate Failed", cust); }catch (Exception e) { fail(e.getMessage()); e.printStackTrace(); } System.out.println("testValidLogin PASSED"); } }
this is my xml file:
whats wrong with it? do i need to add something to xml file???Java Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>myPrice</display-name> <welcome-file-list> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>login.html</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>LoginCtrl</display-name> <servlet-name>LoginCtrl</servlet-name> <servlet-class>controller.LoginCtrl</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginCtrl</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>SearchCtrl</display-name> <servlet-name>SearchCtrl</servlet-name> <servlet-class>controller.SearchCtrl</servlet-class> </servlet> <servlet-mapping> <servlet-name>SearchCtrl</servlet-name> <url-pattern>/send</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>ErrorCtrl</display-name> <servlet-name>ErrorCtrl</servlet-name> <servlet-class>controller.ErrorCtrl</servlet-class> </servlet> <servlet-mapping> <servlet-name>ErrorCtrl</servlet-name> <url-pattern>/error</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>LoginMgr</display-name> <servlet-name>LoginMgr</servlet-name> <servlet-class>manager.LoginMgr</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginMgr</servlet-name> <url-pattern>/LoginMgr</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>HomeCtrl</display-name> <servlet-name>HomeCtrl</servlet-name> <servlet-class>controller.HomeCtrl</servlet-class> </servlet> <servlet-mapping> <servlet-name>HomeCtrl</servlet-name> <url-pattern>/home</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>DisplayCtrl</display-name> <servlet-name>DisplayCtrl</servlet-name> <servlet-class>controller.DisplayCtrl</servlet-class> </servlet> <servlet-mapping> <servlet-name>DisplayCtrl</servlet-name> <url-pattern>/display</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>ErrorDisplay</display-name> <servlet-name>ErrorDisplay</servlet-name> <servlet-class>controller.ErrorDisplay</servlet-class> </servlet> <servlet-mapping> <servlet-name>ErrorDisplay</servlet-name> <url-pattern>/errordisplay</url-pattern> </servlet-mapping> <env-entry> <env-entry-name>ICustomerSvc</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>service.CustomerServiceImpl</env-entry-value> </env-entry> </web-app>
Also I checked the logger and found out that the factory has an implementation method and its not returning anything back to the factory.
this is my factory code:
Java Code:package service; import javax.naming.Context; import org.apache.log4j.*; import javax.naming.InitialContext; import org.apache.log4j.*; import controller.LoginCtrl; import exception.*; public class Factory { private static Logger logger = Logger.getLogger(Factory.class); private Factory() { } private static Factory factory = new Factory(); public static Factory getInstance() { return factory; } public IService getService(String serviceName) throws Exception { logger.info("Getting service from factory now"); try { @SuppressWarnings("rawtypes") Class c = Class.forName(getImplName(serviceName)); System.out.println(" c value is" +c); return (IService) c.newInstance(); } catch (ServiceLoadException e) { throw new ServiceLoadException(serviceName + " not loaded"); } catch (ClassNotFoundException e) { throw new ServiceLoadException(serviceName + " not found"); } catch (InstantiationException e) { throw new ServiceLoadException(serviceName + " not instantiated"); } catch (IllegalAccessException e) { throw new ServiceLoadException(serviceName + " illegal access"); } } private String getImplName(String serviceName) throws Exception { logger.info("Inside Impl method now"); Context iniCtx = new InitialContext(); Context envCtx = (Context) iniCtx.lookup("java:comp/env"); return (String)envCtx.lookup(serviceName); } }
Similar Threads
-
JUnit
By cka in forum EclipseReplies: 3Last Post: 07-27-2010, 04:14 PM -
Junit on Jar Files
By mecrazycoder in forum NetBeansReplies: 0Last Post: 07-01-2009, 11:12 AM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 05:15 PM -
Junit
By Azndaddy in forum New To JavaReplies: 6Last Post: 06-15-2008, 06:47 AM -
TRying to use jUnit for Tesing
By sandor in forum New To JavaReplies: 3Last Post: 04-18-2007, 11:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks