• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

Error running Java Unit Test. Don’t manage to import packages related to annotation “@Test” and method “equalTo()”

April 11, 2020 by

Questions › Error running Java Unit Test. Don’t manage to import packages related to annotation “@Test” and method “equalTo()”
0
Vote Up
Vote Down
Garmaine asked 3 years ago

Please help me. I am trying to run a unit test in a Java code (simple code I am running as part of Java trainning), but I don't manage to import the packages related to the annotation "@Test" and method "equalTo()" in AccountTest class (see the code below).

Here is the setup information:

  • I have tried to run this code using IDE's "Eclipse Java Oxygen" and "Eclipse IDE for Java Developers – 2020-03";
  • I have updated the JDK to version 13 (I have updated PATH system variable adding the file directory "C:\Program Files\Java\jdk-13.0.2\bin");
  • I am using JRE 1.8.0_241;
  • OS: Windows 7 Professional;

Code of Unit Test (here is the problem), AccountTest class:

public class AccountTest {

    @Test // Eclipse error reported: "Test cannot be resolved to a type". It does not offer to import the package related to the annotation "@Test"
    public void onWithdrawalBalanceShouldBeReduced() {
        Account account = new Account(200d);
        account.withdraw(50d);

        assertThat(account.getBalance(), is(equalTo(150d))); // Eclipse error reported: "The method equalTo(Double) is undefined for the type AccountTest". It does not offer to import the package related to method "equalTo()"
    }
}

Code for Account Class:

public class Account {

    private double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    public void withdraw(double value) {
        this.balance = this.balance + value;
    }

    public void deposit(double valor) {
        this.balance = this.balance + valor;
    }

    public void setBalance(double saldo) {
        this.balance = saldo;
    }

    public double getBalance() {
        return balance;
    }
}

Code for Bank Class:

public class Bank {

    public void deposit(Account account, double value) {
        account.deposit(value);
    }

    public void doTranference(Account account1, double value, Account account2) {
        account1.withdraw(value);
        account2.deposit(value);
    }
}
Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: java, unit-testing

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Copyright © 2023