Tests

Java

Recommending JUnit. Add the following dependency to pom.xml in your workspace.


```java
<!-- Check available versions at https://mvnrepository.com/artifact/junit/junit -->
<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.13.2</version>
	<scope>test</scope>
</dependency>
```

Create directory structure src/test/java in workspace.
Create test file "ExampleTest.java" in src/test/java.
```
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.junit.Test;

public class ExampleTest {

	@Test
	public void my_test_fail(){
		int one = 1;
		int two = 2;
		assertEquals("This will fail since 1 does not equal 2", one, two);
	}

	@Test
	public void my_test_success(){
		int one = 1;
		int two = 2;
		assertNotEquals("This will fail since 1 does not equal 2", one, two);
	}
}

```

Run the test from a terminal with "mvn test".

Typescript

Recommending ts-jest, install with "npm i -D ts-jest @types/jest @jest/globals jest".

Add a new script to package.json.

 
```typescript
"test": "jest"
```

Exclude tests from being transpired by excluding the directory in tsconfig.json.

 
```typescript
"test": "jest"
```

```typescript
"exclude": [
		"tests/**/*"
	]
}
```

Create directory "tests" in the workspace. Create the "my-test.test.ts" file in the directory tests.

 
```typescript
describe('Example failing test', () => {
	test('This test should fail since 1 does not equal 2', () => {
		const one : number = 1;
		const two: number = 2;
		expect(one).toBe(two);
	});
});

describe('Example success test', () => {
	test('This test should succeed since 1 does not equal 2', () => {
		const one : number = 1;
		const two: number = 2;
		expect(one).not.toBe(two);
	});
});
```

Run a test from the terminal with "npm run test".