ISBN (String), Title (String), Author (String), publishDate (SimpleDateFormat) 등 다른 클래스의 서적 정보를 가져 와서 설정하는 "Book"클래스에 대한 테스트 코드를 작성하려고합니다. "MMM.dd.yyy"), 가격 (Double) 및 요약 내용 (Blob)을 반환합니다. 코드의 일부 또는 전부에 대해 toString 테스트를 실행하려고하면 (형식 및 문자열을 수없이 설정해야 함) 회) :toString Java 코드를 테스트하는 중 오류가 발생했습니다.
@Test
public void testToString() {
Book testBook6 = new Book();
Title testTitle6 = new Title("Title: Moby Dick, ");
Author testAuthor6 = new Author("Author: Mark Twain, ");
ISBN testISBN6 = new ISBN("ISBN: 000-00-000-0000-0");
testBook6.setTitle(testTitle6);
testBook6.setAuthor(testAuthor6);
testBook6.setISBN(testISBN6);
assertEquals("Title: Moby Dick, Author: Mark Twain, ISBN: 000-00-000-0000-0", testBook6.toString());
}
나는 오류가 나타납니다
org.junit.ComparisonFailure: expected:<[Title: Moby Dick, Author: Mark Twain, ISBN: 000-00-000-0000-0]> but was:<[[email protected]]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at book.application.BookTest.testToString(BookTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
을하고 내 스크랩북에 코드를 실행하려고 할 때 : 무슨 일이 일어나고 있는지 볼 수
Book testBook = new Book();
ISBN testISBN = new ISBN("ISBN: 000-00-000-0000-0");
Title testTitle = new Title("Title: Moby Dick, ");
Author testAuthor = new Author("Author: Mark Twain, ");
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat ("MMMM.dd.yyyy");
Price testPrice = new Price(2.25);
Blob testBlob = new Blob("Blah, Blah, Blah");
testBook.setISBN(testISBN);
testBook.setTitle(testTitle);
testBook.setAuthor(testAuthor);
testBook.setPrice(testPrice);
testBook.setBlob(testBlob);
System.out.println(testBook.toString());
, 나는 단지 무작위로 내가 그것을 실행할 때마다 변경 (예 : 1794d431 등) 번호 "[email protected]"의 수익을 얻을 수 있습니다. 모든 테스트는 "Book"이 가져오고 설정하는 모든 클래스를 통과하며 오류가 표시되지 않습니다. 이것은 제 2 차 자바 프로젝트 일뿐입니다. 그러나, 나는 벽을 치고 확실히 어떤 도움을 사용할 수 있었다!
미리 감사드립니다.
package book.application;
import java.time.LocalDate;
public class Book {
//fields
private ISBN ISBN;
private Title Title;
private Author Author;
private LocalDate publishDate;
private Price Price;
private Blob Blob;
//getters and setters
public LocalDate getPublishDate() {
return publishDate;
}
public void setPublishDate(LocalDate publishDate) {
this.publishDate = publishDate;
}
public ISBN getISBN() {
return ISBN;
}
public void setISBN(ISBN ISBN) {
this.ISBN = ISBN;
}
public Title getTitle() {
return Title;
}
public void setTitle(Title Title) {
this.Title = Title;
}
public Author getAuthor() {
return Author;
}
public void setAuthor(Author Author) {
this.Author = Author;
}
public Price getPrice() {
return Price;
}
public void setPrice(Price Price) {
this.Price = Price;
}
public Blob getBlob() {
return Blob;
}
public void setBlob(Blob Blob) {
this.Blob = Blob;
}
@Override
public String toString() {
return "Title: " + this.getTitle().getTitle() + ", Author: " + this.getAuthor().getAuthor() + ", ISBN: " + this.getISBN().getISBN() + ", Published on: " + LocalDate.now() + ", costing: $" + this.getPrice().getPrice();
}
}
정확히 무엇을 묻고 있습니까? – ItamarG3
당신의 Book 클래스는 어디에 있습니까? – developer