Should simple JavaBeans that have only simple getters and setters be unit tested??
What about Beans with some logic in getters and setters?
|
What is currently the best tool for JavaME unit testing? I´ve never really used unit testing before (shame on me!), so learning curve is important. I would appreciate some pros and ... |
In a nutshell, the hashCode contract, according to Java's object.hashCode():
- The hash code shouldn't change unless something affecting equals() changes
- equals() implies hash codes are ==
Let's assume interest primarily in immutable data objects ... |
I am writing unit tests for a class, which has a static final variable.
However, since the state of the static final var is modified in each test, I need some way ... |
I am building an application that queries a web service. The data in the database varies and changes over time. How do I build a unit test for this ... |
I'm writing an implementation of an interface provided by Sun and I'm wondering if anyone knows of the availability of unit tests for Sun's APIs.
It would seem that such of thing ... |
I'm currently debugging some fairly complex persistence code, and trying to increase test coverage whilst I'm at it.
Some of the bugs I'm finding against the production code require large, and very ... |
|
I am writing a simulation of Bananagrams. Currently, I have a GameMaster class that maintains the common collection of pieces. The deal(Player) method deals a certain number of pieces to that ... |
I am writing a Java program that downloads and then processes many webpages. What is the best practice for testing a component of the program that downloads a page without ... |
Any tool for automatically generating unit tests for Java code?
UPDATE:
Primary intended use is to quickly generate unit tests for legacy code that is going to be refactored. No need to ... |
I'd like to run my Java Card applications in some kind of emulated/simulated environment to be able to run JUnit (or any other unit test framework) tests on them. ... |
Is there any tool or framework able to make it easier to test distributed software written in Java? My system under test is a peer-to-peer software, and I'd like to perform ... |
Could a sensible unit test be written for this code which extracts a rar archive by delegating it to a capable tool on the host system if one exists?
I can write ... |
Googled for a Xml Dom open source library that ships with unit tests, but could not find any. Are there any dom libraries, java or .net that have unit tests?
|
Java's ServiceLoader needs those entries to be present inside the JAR file. Is there a way to programatically add those service entries at runtime time for unit testing, when inside the ... |
I am writing a small utility for calculating a complicated mathematical formula (using commons-math library for integration and root finding). I was trying to write it in the same way as ... |
A JUnit book says " protected method ... this is one reason the test classes are located in the same package as the classes they are testing"
Can someone share their experience ... |
In attempts of 100% code coverage, I came across a situation where I need to unit test block of code that catches an InterruptedException. How does one correctly unit test for ... |
I have a program and I am trying to write my Unit Test for it, I just need to know if it is correct? Here is the program:
public static int[] ...
|
I am trying to do some Unit Testing on my program and I need to test if an array is equal to another array so I need to write the code ... |
I have a complex class (300+ lines), which I'm trying to test from different "points of view". I've already created three different unit tests. Every test is a complex class itself ... |
Assume I have built a MVC web apps written using Java.
Now I want to write unit tests for the web apps, what kind of unit testings should be done for a ... |
According to this example, it goes in the same package as the controller it tests.
Why is that necesssary?
I think it would be tidier to have all of my ... |
What are the technologies out there? (I only know of JUnit)
What is the most popular?
Can you please explain the pros/cons of each?
Thanks Alot!!
|
I have a DeliveryScheduleParser class that reads in a spreadsheet and parses it into a number of objects that all end up in a client object that is returned by the ... |
How to unit test the following piece of code:
@Override
public void update() {
if (isStopped() || isPaused()) {
return;
}
// ...
}
This method is from an ... |
As part of a Java assignment i have written a Payroll program. The programm generates 2 files: payslip and report. The payslip contains all the details for each employee e.g. name, ... |
I have a question about memory management/memory leaks that I would like clarification on.
Set Up:
I am testing some servlet code that takes HttpServletRequest and HttpResponse objects references HttpServletRequest#getParameter(String), HttpServletRequest#getHeader(String) and HttpServletRequest#getAttribute(String).
I ... |
i have spring project that consists of a parent and few child projects.
the build is maven-based and the continous integration server is hudson.
i need to choose the way the unit tests ... |
How can I get info about unit test cases that the developers of the JDK performed on the JDK classes?
|
Referred this question first. But seems my context is different.
I'll try to be short and simple. (Just the code I'm putting out is quite big ;)
I have some ... |
I have setter functions that check their input data by passing it to a validation function before changing private variables. If the data is invalid, the getter functions throw an exception. ... |
I'm looking to introduce automated unit testing to a large body of existing Oracle PL/SQL functions, procedures, and types. I would like to use an existing framework that is conceptually as ... |
There seems to be two trends on this topic:
- Some answers (such as this one) suggest unit tests should not log anything.
- Some questions and answers (such as this one) suggest ...
|
I have read a lot about unit testing, but I still haven't found any good examples that would show why unit testing is worth the time.
I would like to see actual ... |
I have a class which calculates a date and I'm wondering how best to test this. I've come up with two approaches and wonder about your thoughts on which is ... |
I am doing some J2ME API test and I found MockME seems like a perfect tool for me, but I didn't found much tutorial about this framework and It seems not ... |
I'm looking into new frameworks to perform some unit testing on a java project. I am aware of junit, but beyond that I haven't found much of consequence. Are there any ... |
What is the most accepted way to name a unit test method when the target has overloads. Consider these methods:
doSomething();
doSomething(String);
How would you name the corresponding test methods? Would this be the ... |
I have a cfc that relies heavily on a Java object (created via JavaLoader) for a lot of its core functionality that I'd like to write some tests for and I'm ... |
I have a class which has a well-defined responsibility - to "Enrich" an object with the information it needs. This information is gathered from a variety of sources (Services). Eg:
public class ...
|
I want to make sure that a given group of objects is immutable.
I was thinking about something along the lines of:
- check if every field is private final
- check if class is final
- check ...
|
- How to write a unit test framework?
- Can anyone suggest some good reading?
I wish to work on basic building blocks that we use as programmers, so I am ... |
More complete question is, given a dependency that expects a callback as a parameter, how do I write a unit test that covers the callback logic and still manage to mock ... |
I have implemented a ShoppingCart where the CartItems are put in a Set to avoid duplicate items. I want to test putting items in cart and persisting in db, and then ... |
I have method that takes 2 integers as arguments and returns:
public int method(int a, int b){
return Math.round((Math.abs(a-b)/3) - (Math.min(a,b)-1500)/10)
}
I have created unit test, which passes for ... |
I am currently testing a part of my application (that we will assume is a class named X) that takes as parameter a reflection java Method, and will print some java ... |
|
|
|
|
How to design using unit test (Java in General forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java Java in General How to design using unit test Post by: John Vorwald, Ranch Hand on Nov 19, 2011 08:18:52 I'm not very good at applying unit testing early in the process, I tend to ... |
|
public boolean gotoStartPosition(Player player) { boolean returnBool = true; if (player!=null){ for(Chest chest : playground.chestList) { if((chest.getXIndex() == player.getXStart()) && (chest.getYIndex() == player.getYStart())) returnBool = false; } if((player.getXIndex() == player.getXStart()) && (player.getYIndex() == player.getYStart())) returnBool = false; if(returnBool == true) { player.setXIndex(player.getXStart()); player.setYIndex(player.getYStart()); player.setNumberOfSteps(player.getNumberOfSteps()+5); } return returnBool; } else{ System.out.println("The player class is not instantiated"); } return returnBool; } |
/** * Divide this mony object by the other money * object to produce a dimensionless ratio.For example: * * Money first, second; * * Money result = first.div(second); * * is similar to: * * double first, second; * * double result = first / second; * * @param other the money object to divide into this one. * @return ... |
Folks, I've been tasked with creating test cases for the EJB's of some new functionality. So... I sat down to specify what test cases will be required. It wasn't long before I realised the amount of repetative "boiler plate" code we'd be writing to: * test what every reference-type argument to every EJB method does given null... and * each String ... |
shawnw wrote: OK, I have tried to rap my mind around this for a few days. Unit testing. "Unit" == "one thing". You're testing each individual part of your program that can be considered a single functional unit (not necessarily a single class). Although I've heard people say "unit testing" to apply to just about everything. That works in the sense ... |
You never avoid debugging. Unit tests help you avoid having to use a debugger and painfully stepping through your code. They do this because they can help isolate problems down to individual classes and methods. Of course, unit tests don't help in that way much if you write huge, bloated, do-everything classes that follow a poor object design. So you still ... |
hey I can't get this to work, I get a failure when I test it. I start by creating a startTime and an endTime for an appointment, then I create the appointment, which I call "meeting" and assign the two objects to start and end. But after that I don't know how to get it right. Help public void testAddappointments() { ... |
I've started unit testing of my application using JUnit 4.0. The problem is that most of the important code is handled in private functions that can't be unit tested. What is the protocol here? I'm thinking I'll make all my methods public just for the sake of unit testing, then make them private and use the @ignore annotation in the test ... |
|
I have a method that moves a stage (a hardware device) public void moveLeft(double pos) { . . . } My question is how will I unit test it ?? The only thing it does is, moving the stage depending upon the pos that is passed to it. It does not written anything. Would appreciate any kind of help on this ... |
yea i can tell its the constructor problem but more majorly is how? i'm like new-ish to this array thing and i would appriecate it very much if u can just provide me with a more direct solution. i tried throwing in a constructor like "int[] Math2;" or like "int [] Maths 2 = int [];" and i'm just too noob ... |
I'm doing unit testing on a project and I have a test method that takes an object of any class as a parameter that I would like to run on objects from all classes in my project. This problem could easily be solved by adding a new call to the method (in some file) when I add a new class file ... |
|
|
When you say you leave your tests in the same package are you leaving them in the same project? I set up a separate project for unit testing and run the tests from there. I do mirror the package structure so essentially the tests are in the same package. If you leave them in the same project any advantages to that? ... |
Hi all, I have a question that probably should be in a different forum, but I am not looking for a direct solution to my problem but any information you may know. Now I am doing a tutorial from IBM regarding Spring2 and JPA. I have written a Unit Test but while Junit is loading I get the following exception. As ... |
Hi i have a java project. and inside it i have a class and in that i would like to perform unit testing over few methods, and these methods have void . i would like to know how to start unit testing as i am new to this. i wil place my code if required thankx |
hi, i'm a java developer with 10 years programming experience. although it hasn't always been mandated on some projects i have worked on, i have always written unit tests (junit) for my own code even though most of my fellow team members didn't. i recently joined a new team. i was one of the last to join the team. so, the ... |
Time to restructure your class I'm not so sure. This is a utility class (called DeploymentEnvironmentDetector ) with a single, static, public method detectDeploymentEnvironment(). Behind that public method sit several private methods, one to "detect" based on environment properties, one to detect based on underling host properties (like the hostname), etc. When the public method is called, it calls each of ... |
Hi, I know this is more of a generic programming problem than a specific java one but I've been googling for stuff on best practices when it comes to reviewing JUnit tests. We have a J2EE web based finance application but our unit test coverage leaves a lot to be desired. Any one got any useful urls I could lookup on ... |
|