test测试类

题目

package com.rimi.qbs.service;

import com.rimi.qbs.bean.Question;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

import static org.junit.Assert.*;

/**
 * @author Zhou
 * @date 2019/11/26 10:44
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/spring-service.xml"})
public class IQuestionServiceTest {
    @Autowired
    private IQuestionService questionService;
    @Test
    public void findAllQuestion() {
        //查询所有的题目
        List<Question> list = questionService.findAllQuestion();
        for (Question question : list) {
            System.out.println(question);
        }
    }

    @Test
    public void deleteByQuestionId() {
        //删除数据
        boolean delete = questionService.deleteByQuestionId(1);
        Assert.assertTrue(delete);
    }

    @Test
    public void insertQuestion() {
        //添加数据
        Question question=new Question();
        question.setQId(4);
        question.setQName("java试卷");
        question.setQAnswer("正确的选择");
        question.setQtId(1);
        question.setQbId(3);
        question.setQState(1);
        // 判断是否保存成功
        boolean insertQuestion = questionService.insertQuestion(question);
        Assert.assertTrue(insertQuestion);
        System.out.println(question);
    }
}

答案类

package com.rimi.qbs.service;

import com.rimi.qbs.bean.Answer;
import com.rimi.qbs.service.impl.AnswerServiceImpl;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

import static org.junit.Assert.*;

/**
 * @author Zhou
 * @date 2019/11/26 9:10
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:config/spring-service.xml"})
public class IAnswerServiceTest {

    @Autowired
    private IAnswerService answerService;


    @Test
    public void findAllAnswer() {
        //查询所有答案表
        List<Answer> list = answerService.findAllAnswer();
        for (Answer answer1 : list) {
            System.out.println(answer1);
        }
    }
    @Test
    public void findByAnswerId() {
        //根据答案id查询
        Answer answer= new Answer();
        List<Answer> list = answerService.findByAnswerParam(answer);
        for (Answer answer2 : list) {
            System.out.println(answer2);
        }
    }
    @Test
    public void insertAnswer() {
        //添加数据
        Answer answer= new Answer();
        answer.setAnId(6);
        answer.setAnContent("java开发");
        answer.setAnOptions("B");
        answer.setQId(2);
        boolean insertAnswer =answerService.insertAnswer(answer);
        // 判断是否保存成功
        Assert.assertTrue(insertAnswer);
        System.out.println(answer);
    }

    @Test
    public void deleteByAnswerId() {
        //删除
        boolean delete =answerService.deleteByAnswerId(6);
        Assert.assertTrue(delete);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值