English 中文(简体)
在JUM测试中我如何测试名单?
原标题:How do I test a list in a JUnit test?

我创建了一个调查.java课程和一个调查测试.java JUM测试。但我不确定如何在调查类中测试名单。我如何在JUU测试中测试它们?

调查.java

package com.jhaksurvey.model;

import java.util.List;

public class Survey {

private long id;
private String title;
private boolean active = true;
private List<Question> questions;

public Survey() {

}

public Survey(long id, String title) {
this.id=id;
this.title=title;   
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public List<Question> getQuestions() {
return questions;
}

public void setQuestions(List<Question> questions) {
this.questions = questions;
}

}

调查试验.java

package com.survey.model.test;

import junit.framework.Assert;
import junit.framework.TestCase;

import com.survey.model.Survey;


public class SurveyTest extends TestCase {

private Survey survey;

protected void setUp() throws Exception {
    super.setUp();  
    survey = new Survey();
}

public void testSurvey() {
    survey.toString();
}

public void testSurveyLongString() {
    fail("Not yet implemented");
}

public void testGetId() {
    long expected = (long) Math.random();
    survey.setId(expected);
    long actual = survey.getId();
    Assert.assertEquals(expected, actual);
}

public void testGetTitle() {
    String expected = "surveytitle";
    survey.setTitle(expected);
    String actual = survey.getTitle();
    Assert.assertEquals(expected, actual);  
}

public void testIsActive() {
    Boolean expected = true;
    survey.setActive(expected);
    Boolean actual = survey.isActive();
    Assert.assertEquals(expected, actual);
}

public void testGetQuestions() {
    fail("Not yet implemented");
}

}
最佳回答

这门课没有真正的逻辑,所以你不需要测试这门课。你只应该测试含有某种逻辑的班级。

问题回答

rove. java 是用于顶值的模型/数据结构。 理想情况下, 您应该测试使用调查类的类别。 对于 ex. CreateSuvey 可能是正在创建调查的类别, 这样您就可以单位测试创建方法, 以确保它能够适当设定调查对象的值 。

您可以测试列表是否无效





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签