Skip to content

Commit

Permalink
Fim Curso: Testes Unitários Com JUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
ducrz committed May 24, 2022
1 parent 9988c80 commit 4e3f67d
Show file tree
Hide file tree
Showing 28 changed files with 964 additions and 0 deletions.
Binary file not shown.
8 changes: 8 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/aula01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Instrutor: Willyan Caetano.


Testes Unitários com JUnit


Apresentação do Curso

2 changes: 2 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/aula02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Por que escrever Testes Unitários?

1 change: 1 addition & 0 deletions Java/Testes-Unitarios-com-JUnit/aula03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World, JUnit!
8 changes: 8 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/aula04.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Aprofundando nos Recursos

O básico para testar
Mais algumas asserções
After e Before
Assumptions e Testes condicionais
Testando exceptions
Ordenando testes
5 changes: 5 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/aula05.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Recursos de Testes nas IDEs

Visual Studio Code
Eclipse
IntelliJ IDEA
1 change: 1 addition & 0 deletions Java/Testes-Unitarios-com-JUnit/aula06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Boas Práticas
1 change: 1 addition & 0 deletions Java/Testes-Unitarios-com-JUnit/aula07.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conclusão do Curso
84 changes: 84 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/junit5-exemplos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace

##############################
## OS X
##############################
.DS_Store
31 changes: 31 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/junit5-exemplos/CONFIGURACAO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Configurando JUnit

## Maven

Adicionar no `pom.xml` do projeto a dependência abaixo:

```xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
```
## Gradle

Adicionar ao arquivo `build.gradle` `testImplementation` no closure `dependencies` e `useJUnitPlatform()` no closure `test`, ficando mais ou menos assim.

```groovy
dependencies {
//demais dependências do projeto
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2'
}
test {
useJUnitPlatform()
}
```

Observação: A versão escolhida acima, `5.8.2`, escolhida nos exemplos, era a mais recente até o momento deste manual. Verificar versão mais nova em [Maven Repository](https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine).
21 changes: 21 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/junit5-exemplos/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Willyan Guimarães Caetano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/junit5-exemplos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Testes unitários com JUnit

Respositório com roteiros e exemplos de como utilizar JUnit no seu dia a dia como dev.
Foi utilizado para os exemplos a versão 5.8.2, mais atual até o momento (29/01/2022).

## Roteiros

1. [Configurando JUnit](CONFIGURACAO.md)

112 changes: 112 additions & 0 deletions Java/Testes-Unitarios-com-JUnit/junit5-exemplos/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<name>junit5-exemplos</name>
<artifactId>junit5-exemplos</artifactId>
<groupId>one.digitalinnovation</groupId>
<version>1.0.0-SNAPSHOT</version>

<description>Repositório com exemplos utilizando JUnit 5</description>

<url>https://github.com/willyancaetano/junit5-exemplos</url>

<licenses>
<license>
<name>MIT</name>
<url>https://spdx.org/licenses/MIT.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<organization>
<name>Digital Innovation One</name>
<url>https://digitalinnovation.one</url>
</organization>

<scm>
<url>https://github.com/willyancaetano/junit5-exemplos</url>
<connection>[email protected]:willyancaetano/junit5-exemplos.git</connection>
<developerConnection>[email protected]:willyancaetano/junit5-exemplos.git</developerConnection>
</scm>

<issueManagement>
<system>Issues</system>
<url>https://github.com/willyancaetano/junit5-exemplos/issues</url>
</issueManagement>

<ciManagement>
<system>Pipelines</system>
<url>https://github.com/willyancaetano/junit5-exemplos/pipelines</url>
</ciManagement>

<developers>
<developer>
<id>willyancaetano</id>
<email>[email protected]</email>
<name>Willyan Guimarães Caetano</name>
<organization>Digital Innovation One</organization>
<organizationUrl>https://digitalinnovation.one</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>America/Sao_Paulo</timezone>
</developer>
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.class>one.digitalinnovation.junit.HelloWorld</main.class>
<java.version>11</java.version>
<junit.jupiter.version>5.8.0</junit.jupiter.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<maven.jar.plugin.version>3.1.1</maven.jar.plugin.version>
<maven.surefire.plugin.version>2.22.1</maven.surefire.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
MIT License
Copyright (c) 2022 Willyan Guimarães Caetano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package com.github.willyancaetano.junit;

public class Conta {

private String numeroConta;

private int saldo;

public Conta(String numeroConta, int saldo) {
this.numeroConta = numeroConta;
this.saldo = saldo;
}

public String getNumeroConta() {
return numeroConta;
}

public int getSaldo() {
return saldo;
}

public void lancaCredito(int valor) {
this.saldo += valor;
}

public void lancaDebito(int valor) {
this.saldo -= valor;
}
}
Loading

0 comments on commit 4e3f67d

Please sign in to comment.