Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_pt
CreateManager_pt
LeftMenu




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateDAO_pt


Difference between version 12 and version 11:

At line 163 changed 1 line.
If you want to change the size of your columns, specify a length=''size'' attribute in your @hibernate.property tag. If you want to make it a required field (NOT NULL), add not-null="true".
Se você quiser alterar o tamanho de suas colunas, especifique um atributo length=tamanho no tag @hibernate.property. Se quiser que ele se torne um campo requerido (NOT NULL), adicione not-null=”true”.
At line 165 changed 1 line.
!!Create a new DaoTest to run JUnit tests on your DAO [#3]
!!Criar uma nova classe DaoTest para executar testes JUnit no DAO [#3]
At line 167 changed 1 line.
Now we'll create a DaoTest to test our DAO works. "Wait a minute," you say, "we haven't created a DAO!" You are correct. However, I've found that [Test-Driven Development|http://www.artima.com/intv/testdriven.html] breeds higher quality software. For years, I thought __write your test before your class__ was hogwash. It just seemed stupid. Then I tried it and I found that it works great. The only reason I do all this test-driven stuff now is because I've found it rapidly speeds up the process of software development.
Agora iremos criar uma classe DaoTest para testar se nosso DAO funciona. “Espere um minuto” você diz, “nós não criamos um DAO!” Você está correto. No entanto, eu descobri que [Desenvolvimento dirigido por Testes|http://www.artima.com/intv/testdriven.html] produz softwares de alta qualidade. Por anos, pensei que __escrever seu teste antes de sua classe__ era tolice. Simplesmente parecia estúpido. Então eu tentei e descobri que funciona notavelmente. A única razão de fazer todo teste desenvolvimento dirigido por teste agora é porque descobri que ele rapidamente aumenta a velocidade do processo de desenvolvimento de software.
At line 169 changed 1 line.
To start, create a PersonDaoTest.java class in the test/dao/**/dao directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html], which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for automatically loading a .properties file (ResourceBundle) that has the same name as your *Test.class. In this example, if you put a PersonDaoTest.properties file in the same directory as PersonDaoTest.java, this file's properties will be available via an "rb" variable.
Para começar, crie uma classe PessoaDaoTest.java no diretório test/dao/**/dao. Esta classe deve estender [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDAOTestCase.java.html], que já existe neste pacote. Esta classe pai é usada para carregar ApplicationContext do [Spring's|http://www.springframework.org] (Spring une todas as camadas), e para automaticamente carregar um arquivo .properties (ResourceBundle) que tem o mesmo nome que sua classe *Test.class. Neste exemplo, se você colocar um arquivo PessoaDAOTest.properties no mesmo diretório que PessoaDAOTest.java, este arquivo de propriedades estará disponível via uma variável “rb”.
At line 171 changed 1 line.
;:%%(color: blue)''I usually copy (open → save as) an existing test (i.e. UserDaoTest.java) and find/replace [[Uu]ser with [[Pp]erson, or whatever the name of my object is.''%%
;:%%(color: blue)''Usualmente copio (abrir salvar como) um teste existente (ex.: UserDaoTest.java) e procurar/substituir [Uu]ser com [Pp]essoa, ou qualquer que seja o nome do meu objeto.''%%
At line 184 added 1 line.
At line 205 changed 1 line.
The code you see above is what we need for a basic JUnit test that initializes and destroys our PersonDao. The "ctx" object is a reference to Spring's ApplicationContext, which is initialized in a static block of the [BaseDaoTestCase's|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html] class.
O código que você vê acima é o que precisamos para um teste JUnit básico, que inicializa e destrói nosso PessoaDAO. O objeto “ctx” é uma referência ao ApplicationContext do Spring, o qual é inicializado em um bloco estático da classe [BaseDaoTestCase's|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html] class.
At line 207 changed 1 line.
Now we need to actually test that the CRUD (create, retrieve, update, delete) methods work in our DAO. To do this we created methods that begin with "test" (all lower case). As long as these methods are public, have a void return type and take no arguments, they will be called by our <junit> task in our Ant build.xml file. Here's some simple tests for testing CRUD. An important thing to remember is that each method (also known as a test), should be autonomous. Add the following methods to your PersonDaoTest.java file:
Agora precisamos realmente testar que os métodos CRUD (Create, Retrieve, Update, Delete) funcionem em nosso DAO. Para fazê-lo, criamos métodos que começam com “test” (tudo letra minúscula). Contanto que estes métodos sejam públicos, tenham o tipo void como retorno e não receba argumentos, eles serão chamados por nossa tarefa <junit> em nosso arquivo build.xml. Aqui esta alguns testes simples para testar CRUD. Uma coisa importante a lembrar é que cada método (também conhecido como test) deve ser autônomo. Adicione os seguintes métodos para seu arquivo PessoaDaoTest.java:

Back to CreateDAO_pt, or to the Page History.