EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
840 stars 342 forks source link

Evosuite not generating test case for DAO package #102

Closed AmalGo90 closed 6 years ago

AmalGo90 commented 7 years ago

Context

I am trying to generate the test case for DAO package but its not getting generated. Seems while generating test case for the BaseDaoSupport it gives me following error. Due to that wherever I extends this BaseDaoSupport that classes also not getting generated.

[INFO] [MASTER] 16:25:31.746 [main] WARN StorageManager - No CSV file for CUT with test suite at C:\TestSpringBoot.evosuite\tmp_2017_03_29_16_15_53\tests\com\wal\acc\dao\impl\BaseDaoSupport_ESTest.java

Can you please assist?

Steps to Reproduce

  1. run this evosuite maven plugin goal to generate test case.

EvoSuite Arguments

clean evosuite:generate evosuite:export test

Expected result

It should generate the test case for the DAO pacakage

Additional info

Please look the below code and provide solution

pom.xml

junitgeneration org.springframework.boot spring-boot-maven-plugin org.codehaus.sonar sonar-maven-plugin 4.5.1 org.evosuite.plugins evosuite-maven-plugin 1.0.4-alpha1 org.apache.maven.plugins maven-surefire-plugin 2.17 listener org.evosuite.runtime.InitializingListener org.apache.maven.plugins maven-compiler-plugin **/model/*.java

BaseDaoSupport .java

package com.wal.acc.dao.impl;

import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.jpa.HibernateEntityManagerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate;

public class BaseDaoSupport {

@Autowired
private JdbcTemplate jdbcTemplate;

@Autowired
private SessionFactory sessionFactory;

@Bean
public SessionFactory sessionFactory(HibernateEntityManagerFactory hemf) {
    return hemf.getSessionFactory();
}

public Session getSession() {
    Session session = sessionFactory.getCurrentSession();
    return session;
}

public JdbcTemplate getJdbcTemplate() {
    return jdbcTemplate;
}

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

}

SpringBootDaoImpl.java

package com.wal.acc.dao.impl; import com.wal.acc.dao.api.SpringBootDao; import java.util.; import java.util.logging.Logger; import org.hibernate.Criteria; import org.springframework.stereotype.Repository; import com.wal.acc.dto.jaxb.; import com.wal.acc.common.DAOException; import com.wal.acc.dao.impl.BaseDaoSupport; import com.wal.acc.model.Automation;

@Repository public class SpringBootDaoImpl extends BaseDaoSupport implements SpringBootDao {

private static final Logger logger = Logger
        .getLogger(SpringBootDaoImpl.class.getName());

@Override
public String getBoot(RequestVO requestVO) throws DAOException {
    logger.info("dao getBoot started");
    Criteria criteria = getSession().createCriteria(Automation.class);
    //criteria.add(Restrictions.eq("id", requestVO.getId()));
    List<Automation> id = criteria.list();
    String a = null;
    for(Automation automation : id){
        a = automation.getText();
    }
    return a;
}

@Override
public List<String> getBootSpring(RequestVO requestVO) throws DAOException {
    logger.info("dao getBootSpring started");
    List<String> list = new ArrayList<String>();
    list.add(requestVO.getId());
    Automation automation = new Automation();
    automation.setId((short) 22);
    automation.setText("am"+requestVO.getId());
    getSession().save(automation);      
    return list;
}

}

If I remove "extends BaseDaoSupport " from my DAO impl, test case getting generated. But after adding, test case not getting generated. Please assist.

AmalGo90 commented 7 years ago

could you please update?

karthikjeyapal commented 7 years ago

same issues only i'm facing please provide suggestions

AmalGo90 commented 7 years ago

Hi Sina,

can you please share an update?

gofraser commented 7 years ago

Asking every couple of hours will not get this problem solved quicker.

Can you please provide a complete pom.xml rather than an excerpt so that we can build your example.

gofraser commented 7 years ago

@AmalGo90 if you want me to fix this, can you please produce a minimal example. I cannot run your source code example because I don't know what the dependencies are, and I don't have all dependencies that are imported. (Same holds for #99)

gofraser commented 6 years ago

Since I cannot reproduce this, I am closing this issue.

dilagurung commented 4 years ago

getting the same issue