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

Scout SDk usage in command line
Error creating bean with name '_muleSimpleRegistryBootstrap
“Step” or “Job” Scope for Spring-Batch beans?
WebSphere 8.5 - Linux OS problems in simple log output
How to get hardware device serial number with help of ip address?
Why &= operator doesn't work the same as &&
Best practices for dealing with exceptions in a synchronized block/method in Java [closed]
Container of Enums in java
Map Type , HashMap constructor [duplicate]
Applying blur using RenderScript in Android creates weird output
Convert regular date and time to Julian date and vice versa
Java NoClassDefFoundError, Not Sure What's Wrong
Not sure I am using inheritance/polymorphism issue?
Finding the Mode of Integers in an Array
How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?
Access Canvas From JFrame

Categories

HOME
amazon-ec2
octobercms
bookshelf.js
mvvmcross
swagger-ui
esper
volttron
spring-xd
floating-action-button
quickbooks
etl
size
decimal
fatal-error
undefined
opencover
excel-2007
delicious-api
srcset
flink-streaming
google-rich-snippets
exuberant-ctags
jspresso
column-family
form-data
bower-install
jmonkeyengine
git-merge
dartium
serverside-rendering
service-discovery
sql-server-agent
nxlog
unixodbc
reactive-cocoa-5
avconv
jquery-nestable
boost-multi-index
mplayer
magma
sqldf
vtigercrm
quartz-composer
pycaffe
instant
infix-notation
transmitfile
google-web-starter-kit
ptrace
jfugue
unity-networking
maven-tomcat-plugin
intel-fortran
atk4
sysinternals
sortedlist
truevault
c++03
bigbluebutton
jsonpickle
android-nested-fragment
applescript-objc
websocket4net
internet-connection
responsive-slides
sgen
hippomocks
comexception
seaside
uv-mapping
mysqltuner
ccss
spring-io
eclipse-memory-analyzer
jelly
google-email-migration
frameset
armcc
parametric-equations
wse3.0
reddot
postgresql-performance
punbb
window-management
deobfuscation
recent-documents
ecl
zend-translate
sector
rtml

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