简体   繁体   中英

JUnit Testing with Object Fixture

Hey guys I'm trying to write a JUnit test to test something but it's just not clicking. I'm supposed to design a jUnit tester that is testing a class but uses another class that implements the original class as a test fixture.

I'm supposed to make a generic circular array that has some methods for certain things such as adding to the front of the array and back, etc. I'm not quite sure I've implemented the Array casting correctly as you can't cast a generic type array but we've been asked to use a bounded wildcard so I think the way I implemented it is okay....here it is sans comments

public class Array12<E> implements LimCapList<E>
{
private int maxSize;
private int first;
private int last;
private int size;
private E[] A12;

@SuppressWarnings("rawtypes")
public Array12(Class <? extends E> clazz, int capacity)
{
    this.maxSize = capacity;
    this.size = 0;
    this.first = 0;
    this.last = 0;
    @SuppressWarnings({ "unchecked", "unused" })
    Array12 A12 = new Array12(clazz, capacity);
}

Now what I want the function to do is to create a circular Array of type clazz, with size capacity. Did I implement it correctly? The reason why I ask is because when I try to create the jUnit tester, I run into a wall and am pretty stuck on what I need to do to get it going. Here is what I've got so far for the jUnit tester....

public class LimCapListTester extends junit.framework.TestCase
{
private Array12 array12;

protected void setUP()
{
    array12 = new Array12(Class<String>, 0);
}

protected void tearDown()
{
    array12 = null;
}

Problem is, array12 = new Array12(Class, 0);

Doesn't seem to be working correctly. And I'm not sure if I'm just using the wrong syntax in the jUnit tester or if I wrote my Array12 incorrectly. Any hints on how to fix it?

DISCLAIMER This is for a homework assignment so I'm not looking for a solution, but rather a hint on where I made a coding error and maybe some more insight on how to write jUnit testers with a different test fixture as all I've had experience with so far is writing a jUnit test for a specific class. For example, I wrote a List12.java that implements LinkedLists and wrote a List12Tester.java that worked fine. However, in this assignment I need to write a SomeTester.java that tests SomeCode.class but uses Array12 which implements SomeCode.class as a test fixture.

I hope I've explained it as best as I can as I'm really confused and I do plan to ask my TAs for help but I figure maybe someone could help me out so I don't look TOO stupid when asking my TA in case the answer is really obvious. :) Thanks guys!

Hint: check the signatures of the methods of junit.framework.TestCase . When overriding a method in a super class, it's best to use @Override

@Override
protected void tearDown() {
  array12 = null;
}

If tearDown() wasn't a method in a super class, then the compiler would complain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM