#error in my toString tests pls help

1 messages ยท Page 1 of 1 (latest)

sterile cave
#

will upload pictures in a second

coarse caveBOT
#

<@&987246883653156906> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Will upload pictures in a second

When writing tests for your toString method in Java, ensure that you are comparing the expected output with the actual output correctly.

Make sure that the expected string matches exactly what you are expecting from your toString method. Be mindful of whitespaces, formatting, and any special characters that might be included in the output.

Check that you are calling the toString method on the correct object instance and that you are providing valid input data for the test.

If you are encountering errors in your tests, consider debugging by adding print statements or breakpoints to see the actual output being generated by your toString method.

Additionally, make sure that your test setup is correct and that all necessary dependencies or configurations are in place before running your tests.

If you continue to experience issues with your toString tests, consider seeking help from fellow developers on forums or communities like this one for further assistance. When uploading pictures to illustrate the problem, make sure they clearly show the relevant code snippets and error messages for others to provide more targeted support.

sterile cave
crude sparrow
#

Please share your code as text.

sterile cave
#

mkmk

#

package Test;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import Main.NonElecCar;

public class NonElecCarTest {

NonElecCar NElec;

@Before
public void testGetFueltype() {
    NElec = new NonElecCar("Mitsubishi", "Mirage", 2017, "GHI789", "JKL101", 4, "Petrol");
}

@Test
public void getMake() {
    assertEquals("Mitsubishi", NElec.getMake());
}

@Test
public void getModel() {
    assertEquals("Mirage", NElec.getModel());
}

@Test
public void getYearofReg() {
    assertEquals(2017, NElec.getYearofReg());
}

@Test
public void getRegNum() {
    assertEquals("GHI789", NElec.getRegNum());
}

@Test
public void getLicenceNum() {
    assertEquals("JKL101", NElec.getLicenceNum());
}

@Test
public void getDoors() {
    assertEquals(4, NElec.getDoors());
}

@Test
public void getFueltype() {
    assertEquals("Petrol", NElec.getFueltype());
}

@Test
public void testToString() {
    String expectedOutput = "NonElecCar [make=Mitsubishi, model=Mirage, yearofReg=2017, regNum=GHI789, licenceNum=JKL101, doors=4, fuelType=Petrol]";
    assertEquals(expectedOutput, NElec.toString());

}

}

#

this is the one that is erroring at the end

crude sparrow
#

And you're using a default toString, so if you want something different just alter the implementation?

sterile cave
#

yes i have to add data from my sql after i have finished with the initial code and tests

#

sorry if i dont understand what u mean im v new w java

crude sparrow
#

You have a toString method.

#

In there you can build the String you build yourself.

sterile cave
#

i think i just got it working just sorry for wasting time

crude sparrow
#

No worries.