java


Can I do a jUnit Test in the Same Class as My Main Code?


I am new to jUnit and I am finding testing the small project I'm working on difficult. All the examples for jUnit testing seem to involve math, and what I wrote is a simple application that takes information via Scanner and creates various objects and stores them in an ArrayList. One of my thoughts was to test if the ArrayList was empty, but I obviously cannot access it from a separate class, but the standard seems to be to separate the test from the code. So I am not sure what to do?
You could provide a protected accessor for the array so that it can be used by the unit tests (which should be in the same package).
The typical well established practices are:
Unit test and production code goes into different files living in different projects but using the same package names.
Unit tests should not rely on internal state of production code. You don't want to write a test that needs to know about a field within the class under test. Because that means that your test can break when you change the production code to solve the problem differently.
The real answer here: you should share pieces of your code with us, to receive really helpful feedback.

Related Links

java.lang.NoClassDefFoundError: org/python/util/PythonInterpreter
“Block” ArrayList size
In a construct of the following if - else if - else if structure, how many comparisons are made, 1 or 3?
Replacing all special characters, numbers and alphabets
SINGLE_TABLE inheritance strategy discriminating based on parent table
Android studio error RuntimeException: Unclosed ': Unclosed '
How to point to jdk1.8 in eclipse juno?
Get list of all files in a directory inside assets
Using Ember with Spring.io Framework. Doable or a bad idea? [closed]
VLCJ Can' t open audio streaming using http on client-side
Convert matlab to java
log4j2 loging database varchar2 error
Store date in class
Set the image duration with jcodec in android
Stuck with Java Generic Classes
Java SSO with using waffle in Tomcat

Categories

HOME
atom-editor
coq
reserved
grep
webstorm
append
webrequest
iggrid
maude-system
dax
rascal
mapserver
zend-framework3
graphlab
invantive-sql
google-cloud-speech
jtextfield
grails3
amazonsellercentral
riot.js
wijmo
hammerspoon
android-widget
info.plist
atlassian-crucible
objectanimator
primitive
media-queries
bcd
code-contracts
vsts-build-task
gammu
http-referer
catalog
suricata
dartium
service-discovery
sqlite2
document.write
dism
bootstrap-dialog
acoustics
auto-update
smartcontracts
return-value
integrity
tropo
pearson
pillow
background-service
bonobo
skobbler-maps
mongocsharpdriver
qcustomplot
ready-api
nessus
independentsoft
browser-link
prerequisites
simple-framework
varargs
unity3d-gui
ami
skos
lustre
nsmutabledictionary
sorl-thumbnail
device-manager
preferences
openexr
reactfx
htmlcleaner
hippomocks
braille
java.nio.file
spring-io
ruby-datamapper
enterprisedb
free-variable
referrer
manchester-syntax
multipage
jspinclude
regsvr32
eclipse-templates
gnustep
gcj
servicehost
pyinotify
floating
remember-me
sproutcore-2
routedevent
yagni
procedural-music
ajax-forms

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App