未使用的方法对未使用的方法有警告,可以删除,例如在 Eclipse 中
MyClass 类型的方法 myMethod() 从未在本地使用
但有时你用它的单元测试编写代码,然后代码在生产中没有使用(或删除),但方法仍然(仅)用于单元测试
我们如何才能找到实际代码中没有使用的这些未使用的方法(仅测试代码)
- 我的测试在 tests 文件夹下,代码在 src 文件夹下
例如 DAO 方法:
public interface TransactionDao {
public boolean updateTrasaction(int id);
}
@Repository
public class TransactionDaoImpl implements TransactionDao {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public boolean updateTrasaction(int id) {
return (jdbcTemplate.update(... )>0);
}
}
仅用于测试:
@Test
public void testUpdateTrasaction() {
Assert.assertEquals(transactionDao.updateTrasaction(1234), true);
}
我知道静态分析工具和 Halting Problem,但是,是否有针对此特定要求的解决方案?