Database Junit Testing

May 28, 2014

I have been designing a music collection application that runs from a database. I now need to develop a junit test to test the application but I am not sure if Junit has anything to work with testing databases. I have been googling on the internet but most of the search results do not really give any good examples that I can easily follow and adapt to my application. I am using only one table and I would like to test INSERT, UPDATE and DELETE actions and I would also like to test a successful connection.

I once found one tutorial which I cannot find any more that had something that retrieves all the data in the database and stores it in a CSV file and the loops through the CSV file to check or update information.

View Replies


ADVERTISEMENT

Testing Events Within Inner Class Using JUnit?

Apr 17, 2015

How do you test the events within an inner class using JUnit

// File: : events/SomePanel.java
// Purpose: Show use of named inner class listener.
 
import javax.swing.*;
import java.awt.event.*;
class SomePanel extends JPanel {
private JButton myGreetingButton = new JButton("Hello");
private JTextField myGreetingField = new JTextField(20);
 
[Code] .....

Code extract taken from: Java: Inner-class Listeners

Taking the above example, do I need to use myGreetingButton.doClick to trigger this event to test the respective variables/values being used ? Also the Actionlistener inner classes is private so doubt I can access this from JUnit Test class.

View Replies View Related

Setup Virtual Database In JUnit Tests

Mar 26, 2014

First I was using this way how to get connection and all was fine.

con = DriverManager.getConnection("jdbc:derby:memory:datab;create=true");

But now I have to change it to DataSource and how I find out derby had class ClientDataSource for this but for the hell I can't find out how to setup that virtual DB.

ClientDataSource ds = new ClientDataSource();
con = ds.getConnection();

View Replies View Related

How To Make Multiple JUnit Reports

Mar 20, 2015

I am making some Junit Tests that process some files with a parser and the do some other processes. I already have a loop for processing a whole folder at a time. But I want to know how can I do so that for each file it processes I can generate an individual report.

View Replies View Related

Cucumber In Java Through Code Without Using Junit

Sep 2, 2014

i want to use cucumber in java through code. previously i have used it with Junit. but now i need to implement it through coding for the purpose of automating.

View Replies View Related

EJB / EE :: Is That Possible With Junit Or Should It Require Other Tools / Frameworks

Feb 3, 2015

Can EJB be developed with a Test Driven Development approach? Is that possible with Junit or should it require other tools/frameworks?I am also interested in understanding which mocks should I consider and which part of the IJB code must instead be tested?

View Replies View Related

How To Write JUnit Test Classes For Application

Apr 16, 2014

I am working on a class project and I have to write the JUnit test for the GUI class ... what I did wrong ... Here is the code for the GUILauncher:

package edu.oakland.production;
import java.awt.*;
import javax.swing.*;
public class GUILauncher{
public static void main(String[] args){
RetrieveWindow gui = new RetrieveWindow();

[Code] .....

View Replies View Related

Error In Junit ArrayIndexOutOfBounds - Cannot Seem To Find Source

May 12, 2015

I get an error "ArrayIndexOutOfBounds" in my Junit test on the following method:

public String[] getMACs(String ssid) {
int first = bs.searchFirst(arrayWlanMac, new GetSet(null, ssid, 0, 0),
new ComparatorSSID());
int last = bs.searchLast(arrayWlanSsid, new GetSet(null, ssid, 0, 0),

[Code] ....

The error occurs in the first while loop right in the if condition (if (!arrayWlanSsid[i + 1].getMac().equalsIgnoreCase(arrayWlanSsid[i].getMac())) )

View Replies View Related

JUnit Test - Dynamic Fibonacci Rabbits Sequence

May 28, 2014

I'm facing a Problem with the JUnit Test for a Fibonacci rabbits sequence. The JUnit Test should test if the function dynFib(int x) completes the calucation in time. The time given is 100ms. The sequence I wanted to be printed is 0 1 1 2 3 4 6 8 11 15 and I got it but the calculation takes more than 100ms. How can I make it calculate faster without using a loop?

I want to do it recursively and dynamically, I kept trying lots of methods but they did not work.

This is my Code:

public class TestFib {
private static int dynFib(int x, Integer[] array) {
array = new Integer[x + 1];
if (x < 0) {
throw new IllegalArgumentException();

[Code] .....

View Replies View Related

JUnit - Test Class Not Found In Selected Project

Jul 21, 2010

I'm trying to write JUnit test but I'm having trouble with the following errors:

"Test class not found in selected project" -> when running AClassTest.java

"Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class" -> when running AClass.java

I have class AClass.java

and class AClassTest.java

They both are in the same package and there is JUnit library

Here's the code:

AClass.java:

Java Code:

public class AClass {
working code is in the last post
} mh_sh_highlight_all('java');
AClassTest.java:

Java Code: public class AClassTest extends TestCase {

working code is in the last post

} mh_sh_highlight_all('java');

View Replies View Related

Junit Test Case For Reading Field From A File

Feb 17, 2015

I have JUnit exposure only in writing simple programs. Here I have one of the usecases requirement pupose I am generating data file(s) by Java programming and calling this data by Hashmap. My file containing two columns

(1) TimeStamp
(2) Speed.

The file is tab formatted file. The business requirement is to check wether the first column should not be 00000000000000 or NULL or BLANK. My question is, how do I check the first field in a file contaning valid information in Junit test case?

Sample File: ( - tab delimited)
1421103602000 542
0000000000000 989
<NULL> 000
1421103603000 588
1421103604000 700

Unfortunately, I am unable to send my Java code here, It was giving some error while attaching in this thread.

View Replies View Related

Testing TCP Client And Server

Oct 22, 2014

I am attempting to test a TCP Client and Server for an assignment I am doing in class. The goal here is to "test your client and Server applications by transferring (i) a file having 10,000+ lines (see supplied big-file1.txt having 12000+ lines), (ii) a file having 20,000+ lines (you may create one of your own from big-file1.txt, or obtain a large size file from the Google website at [URL] ...). Then, compute and display the total transfer time of the files at both of the sides separately (your choice in millisecond/second)."

I have created the TCPClient and TCPServer java classes, ran the server first and then the client, and using mathematical formulas to calculate the transfer time. Trouble is, I'm having trouble testing the client and server in the file area and not the area where I had to input a line, let the server print it, and then have the client eliminate the articles from the line. I need testing the file. Here is my code so far:

TCPClient:

package tcpclient;
import java.io.*;
import java.net.*;
public class TCPClient {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
String sentence;

[code] ....

How to fix the code so that the time in seconds does not output as 60 for both files and that the files go through the exchange?

View Replies View Related

Testing Boolean Statement

Mar 30, 2015

I wrote a class for encapsulating coins and I was to do a boolean statement but when I test the statement the results are not showing.Here is the code for my coin class coins.java

package project_3;
/**
*
* @author user a
*/
public class Coins {
private double pennies;
private double nickles ;
private double dimes ;
private double quarters ;
private int dollars ;

[code]...

View Replies View Related

Testing Double Null

May 2, 2014

how to execute a particular class. I've created a Kinematics class that will execute and calculate all the functions pertaining to kinematic equations. In the main class, I will have the user provide the data in JTextField. Now I need to test which JTextfields (variables) were left empty. I plan to use a number of if/else statements :

if(distanceI != null && distanceF != null)

The problem with this is that these variables are double and therefore cannot be tested as null. I read a few things about Double but I really don't see how I'm supposed convert each double variable to Double, is that even possible?

public class Kinematics {
double distanceI, distanceF, velocityI, velocityF,
velocityAverage, acceleration;
public Kinematics(){
//v2 = v1 + a*dt
if(distanceI != null && distanceF != null){
 
[code]...

View Replies View Related

String Testing For Null / Empty?

Oct 13, 2014

I've been beavering away with Java for a few months. But as with all languages the String implementation looks designed to trip up even experienced programmers.

My current development gets data from various sources outside my control. When I get a string I want to test if it is empty/null/or whatever. Simple enough one thinks.

But if you search the internet you see everone seems to have a slightly different approach. So what is the best way of determining that a string is not useful to you?

I've had success with this

if(string == null || string.length() == 0)

But I've seen people using methods - not necessarily of String (e.g equals, empty) and regular expressions.

What is the best approach to this considering coding efficiency and/or processing efficiency (accepting you'd have to be processing a lot of strings for the latter to be an issue).

View Replies View Related

EJB / EE :: Bean Annotations And Unit Testing?

Mar 6, 2014

I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.

What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.

What I would like to know is

1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?

2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?

a. Should I throw an exception from the set method of each bean field?

Unit Test:

@Test
public void testName(){
Human h=new Human();
try {
h.setFname("a");
} catch (Exception e) {
// TODO Auto-generated catch block
fail("failed");
e.printStackTrace();

[code]....

View Replies View Related

Syntax Error When Testing Code

Jun 4, 2014

My issue is that when I run the code if I enter anything but 1, 2, or 3 the code breaks. I have spent hours trying to find the error. here is my code

import java.util.Scanner;
public class Tester {
public static void main(String[] args) {
/**
* constructor
* pre: none
* post: inherit values of other classes
*/
Car Car = new Car(); //inherits the properties of the Car class
Truck Truck = new Truck(); //inherits the properties of the Truck class

[code]....

View Replies View Related

Testing Testcase In Junit3 Using Treemap

Apr 22, 2014

I am beginner in Java and facing one problem while testing junit3 testcase using treemap.

The code :
===========================
package sampleJunit3;
import java.util.TreeMap;
import org.junit.*;
import static org.junit.Assert.*;
import junit.framework.TestCase;

[code]....

While running as a Junit Test, test getting failed with error " Test Class not found in selected project".

View Replies View Related

Precision And Recall Testing For Search Engines

May 14, 2014

I have code for precision and recall testing for search engines. I am trying to run it in Newbeans 8.0, but I am getting the common error in UnsupportedOperationException

I have tried making files and directories as the given in the code file. I am attaching the two files here.

Attached File(s)

 PrecisionRecall.rtf (1.79K)
 FSDirectory.rtf (687bytes)
error file-result.rtf (506bytes)

View Replies View Related

Testing Two Mapping Libraries - Orika Vs JMapper

Feb 27, 2014

I have downloaded and testing these two mapping libraries. I wrote a program which has 100000 iterations and maps the beans of the same class:

public class IntBean {
 
    @JMap
    private int int1;
    @JMap
    private int int2;

[Code] ....
 
Mappers are created BEFORE iterations start:
 
    private JMapper jmapper = new JMapper(IntBean.class, IntBean.class);
    private MapperFactory orikaFactory = new DefaultMapperFactory.Builder().build();
    private MapperFacade orikaFacade = null;
orikaFactory.registerClassMap(orikaFactory.classMap(IntBean.class,IntBean.class).byDefault().toClassMap());    orikaFacade = orikaFactory.getMapperFacade(); 

What is in each iteration:this.orikaFacade.map(a1, a2);
or
a2 =  (A) this.jmapper2.getDestination(a1);
 
I know, that Orika and Jmapper are great libraries from Google and they use reflection in a different way than for example Dozer, which is much slower, they se reflection to generete code somehow..

I have 3 questions:

1) How they work - when the code is generated, during maven build, in runtime - everytime when I create mapper in code? Are they change class code byte dynamically?
2) Why there is this speed difference that I noticed?
3) Which library would you choose and why? Both have the same capabilities? Why both come from Google? Why Google didnt develop Orika and created Jmapper instead?

View Replies View Related

Swing/AWT/SWT :: Using Doubles For Positioning Objects And Testing Equality

Aug 15, 2014

I've been noticing some of my programs have been a little buggy recently, and think it's down to confusion over doubles and positioning. Lets say I have a label called banner that I want to scroll across the screen. Now I need to know the label's width in order to position it, but the width depends on the amount of text, so i use this code:

double bannerWidth = banner.getWidth();

Which forces me into using a double if I want to be accurate.

But the problem is that I'm trying to use a condition that compares the label's horizontal position (currentX) to the left edge of the screen (LEFT_EDGE), minus the width of the label (bannerWidth). In other words when the label is off the screen, it should go back to its starting position.

I assume that means that any variables I use to track the label's position (in this case currentX), or constants that I use to check equality (LEFT_EDGE), have to be doubles as well?

My difficulty is that I iterate currentX. But currentX--; won't work because doubles don't iterate as I'd expect.

So casting becomes an option..... but if I cast to an integer I effectively lose width on the label. And that is magnified each loop, resulting in the label's starting position moving further and further to the left.

View Replies View Related

How To Write A Computer Based Testing Program Using Files

Jan 8, 2015

I'm supposed to write a computer based testing program using files. I have started writing however, I am stuck. I am to prompt the user to enter the file name 'test.dat" and if something different is entered then a error message should be displayed. Also the file will create an input stream for the data using the file. I am to have the user enter other information about an employee and then write the record to the file.

The program should be created so when the user enters "quit" the loop is terminated and the file is closed. I'm not asking for code. I was just giving a brief synopsis of the project. Where I am stuck is I wrote the first part of the program that creates the file; however when I enter a wrong file name the exception error message does not display. The code is below:

import java.io.*;
import java.lang.*;
import java.util.*;
public class Project5Write
{
private Formatter x;
public void openFile(){

[Code]...

View Replies View Related

Analyzing And Fixing Failed Cases In Stress Testing

Apr 29, 2014

There are few modules in our application whose performance degrade with time when 50-100 simultaneous users are working on them at a given instance.The memory allocations are taken care of to allow maximum data.My issue to where to start finding the root cause.

I am currenlty using JvisualVM for profiling and finding memory leaks..Do i need to Simualte 50-100 virtual users and start finding the memory leaks with JvisualVM or working with a single user would do ?

View Replies View Related

Rational Number Class - Java Client Code For Testing

Mar 7, 2014

We are making a Rational Number class. After that we must create client code to test it out. The instructions-

•Create 3 instances of RationalNumber. Remember every time you say “new” you are creating an instance.
oOne of them should use the default constructor
oOne of them should use the constructor with one parameter
oOne of them should use the concstructor with two parameters.
•Print out the int and double value of each Rational Number
•Print out the sum (as a double) of all the numbers.
•Print out the sum (as an int) of all the numbers.

My rational number class :

public class RationalNumber{
private int numerator;
private int denominator;
public RationalNumber()
{
numerator =1;
denominator = 4;

[Code] .....

View Replies View Related

JUnit Test - Read From Text Line By Line And Save Words In FileOnTable

Nov 21, 2014

I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?

package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

[Code] ....

View Replies View Related

Using FileRead As Database

Mar 7, 2014

I remember, it's possible to collect multiple parameters from each line in a .txt file (with commas used as delimiters to separate each parameter on each line). My EmployeeData.txt file looks like this:

EDR2014,Bob,Marley,02/12/2011,1000.00
ARR1234,John,Fuzzy,03/23/2013,12.00
XXX0666,Matt,Pagel,08/10/2011,23.00
DIE4273,John,McLane,07/22/1995,45.00
FUK0330,Kevin,Young,12/02/2003,7.00

NFN7734,Sam,Peterson,08/01/1999,8.00

the parameters of each line are: employeeNum, firstName, lastName, hireDate, payRate

To match the specifications in the following EmployeeInfo.java class:

Java Code:

package employeepunch;
//import org.joda.time.DateTime;
import java.io.*;

public class EmployeeInfo {

[code]...

The validation of making sure the employee uses the correct format while entering his employee number is just the first part. I also need to add validation code to make sure his employee number matches one of the ones in the EmployeeData.txt file (shown earlier above).

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved