InputStream in; SqlSessionFactory factory; SqlSession session; UserDao userDao; @BeforeEach public void init() throws IOException { System.out.println("init...."); in = Resources.getResourceAsStream("SqlMapConfig.xml"); factory =new SqlSessionFactoryBuilder().build(in); session =factory.openSession(); userDao = session.getMapper(UserDao.class); } /** * 测试查询所有 */ @Test public void testFindAll() throws IOException { //init(); System.out.println("test...."); List<User> users=userDao.findAll(); for(User user :users) { System.out.println(user.toString()); } } @AfterEach public void close() throws IOException { System.out.println("close...."); in.close(); session.close(); }
一开始 before 和after都没有启动,不知道为什么,查了以后
before 和after被beforeEach和afterEach代替了