题目
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.*;
@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.*;
@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() {
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);
}